home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / Game.EXE_01_2001.iso / demos / Blade of Darkness / data1.cab / Program_Executable_Files / Lib / Actions.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-11-16  |  97.1 KB  |  2,747 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import Bladex
  5. import Ontake
  6. import Stars
  7. import string
  8. import math
  9. import Reference
  10. import Breakings
  11. import InitDataField
  12. import OnInitTake
  13. import AuxFuncs
  14. import B3DLib
  15. import netgame
  16. import Damage
  17. import CharStats
  18. import MenuText
  19. import BInput
  20. import Select
  21. import Netval
  22. import Torchs
  23. import ItemTypes
  24. START_FADEOUT_IN_BIG_FALL = 2.0
  25. END_FADEOUT_IN_BIG_FALL = 2.5
  26. if Reference.DEBUG_INFO == 1:
  27.     import pdb
  28.  
  29. import pdb
  30. TRUE = 1 == 1
  31. FALSE = 1 != 1
  32. RA_NO_WEAPON = 0
  33. RA_1H_WEAPON = 1
  34. RA_BOW = 2
  35. RA_2H_OBJECT = 3
  36. RA_TORCH = 4
  37. LA_NO_WEAPON = 0
  38. LA_SHIELD = 1
  39. LA_BOW = 2
  40. LA_2H_OBJECT = 2
  41. PI = math.pi
  42. TWOPI = PI * 2
  43. FACINGANGLE = PI * 0.125
  44. BEHINDANGLE = PI * 0.75
  45. B_SOLID_MASK_PERSON = 1
  46. B_SOLID_MASK_FLOOR = 2
  47. B_SOLID_MASK_CAMERA = 4
  48. B_SOLID_MASK_PARTICLES = 8
  49. MESSAGE_START_WEAPON = 7
  50. MESSAGE_STOP_WEAPON = 8
  51. MESSAGE_START_TRAIL = 14
  52. MESSAGE_STOP_TRAIL = 15
  53. InterpWithOff = (0,)
  54. InterpWithOutOff = (1,)
  55. InertialIntrp = (2,)
  56. FixedRFootIntep = (3,)
  57. FixedLFootIntep = (4,)
  58. FixedFootAutoInterp = 5
  59. TryToTakeCallBacks = []
  60.  
  61. def ReportMsg(Msg):
  62.     if netgame.GetNetState() == 0:
  63.         import GameText
  64.         GameText.WriteTextAux(MenuText.GetMenuText(Msg), 2.0, 255, 255, 255, [])
  65.     
  66.  
  67.  
  68. def GetListOfObjectsAt(inv, id):
  69.     if inv.GetNumberObjectsAt(id) == 1:
  70.         name = inv.GetObject(id)
  71.         if name:
  72.             return [
  73.                 name]
  74.         else:
  75.             return []
  76.     else:
  77.         corray = range(inv.GetNumberObjectsAt(id))
  78.     resulto = []
  79.     for i in corray:
  80.         name = inv.GetObject(id)
  81.         inv.RemoveObject(name)
  82.         ExtendedTakeObject(inv, name)
  83.         resulto.append(name)
  84.     
  85.     return resulto
  86.  
  87.  
  88. def RemoveAllKeys(EntityName):
  89.     me = Bladex.GetEntity(EntityName)
  90.     inv = me.GetInventory()
  91.     keyNames = []
  92.     for j in range(inv.nKeys):
  93.         keyNames.append(inv.GetKey(j))
  94.     
  95.     for key in keyNames:
  96.         inv.RemoveKey(key)
  97.     
  98.  
  99.  
  100. def RemoveNoTravelObjects(EntityName):
  101.     me = Bladex.GetEntity(EntityName)
  102.     inv = me.GetInventory()
  103.     objname = inv.GetObject(0)
  104.     counterid = 0
  105.     while objname:
  106.         obj = Bladex.GetEntity(objname)
  107.         if obj.Kind in Reference.TravelObjects:
  108.             counterid = counterid + 1
  109.         else:
  110.             inv.RemoveObject(objname)
  111.         objname = inv.GetObject(counterid)
  112.  
  113.  
  114. def PutAllInBack(EntityName):
  115.     me = Bladex.GetEntity(EntityName)
  116.     right = me.InvRight
  117.     left = me.InvLeft
  118.     rightback = me.InvRightBack
  119.     leftback = me.InvLeftBack
  120.     inv = me.GetInventory()
  121.     inv.LinkRightHand('')
  122.     inv.LinkLeftHand('')
  123.     inv.LinkBack('')
  124.     if leftback:
  125.         inv.LinkLeftBack(leftback)
  126.     elif not leftback and left:
  127.         inv.LinkLeftBack(left)
  128.     elif leftback and left:
  129.         print 'ERROR - Actions.PutAllInBack -> leftback and left both diff on none!!!'
  130.         inv.LinkLeftBack(leftback)
  131.         print '   Linked only the back one...'
  132.     
  133.     if rightback:
  134.         inv.LinkRightBack(rightback)
  135.     elif not rightback and right:
  136.         inv.LinkRightBack(right)
  137.     elif rightback and right:
  138.         print 'ERROR - Actions.PutAllInBack -> rightback and right both diff on none!!!'
  139.         inv.LinkRightBack(rightback)
  140.         print '   Linked only the back one...'
  141.     
  142.  
  143.  
  144. def Start_Weapon(EntityName, EventName):
  145.     me = Bladex.GetEntity(EntityName)
  146.     if me:
  147.         inv = me.GetInventory()
  148.         if inv:
  149.             weapon_name = inv.GetActiveWeapon()
  150.             if weapon_name:
  151.                 weapon = Bladex.GetEntity(weapon_name)
  152.                 if weapon:
  153.                     weapon.MessageEvent(Reference.MESSAGE_START_WEAPON, 0, 0)
  154.                 
  155.             
  156.         
  157.     
  158.  
  159.  
  160. def Stop_Weapon(EntityName, EventName):
  161.     me = Bladex.GetEntity(EntityName)
  162.     if me:
  163.         inv = me.GetInventory()
  164.         if inv:
  165.             weapon_name = inv.GetActiveWeapon()
  166.             if weapon_name:
  167.                 weapon = Bladex.GetEntity(weapon_name)
  168.                 if weapon:
  169.                     weapon.MessageEvent(Reference.MESSAGE_STOP_WEAPON, 0, 0)
  170.                 
  171.             
  172.         
  173.     
  174.  
  175.  
  176. def Start_Weapon_Special(EntityName, EventName):
  177.     me = Bladex.GetEntity(EntityName)
  178.     if me:
  179.         inv = me.GetInventory()
  180.         if inv:
  181.             weapon_name = inv.GetActiveWeapon()
  182.             if weapon_name:
  183.                 weapon = Bladex.GetEntity(weapon_name)
  184.                 if weapon:
  185.                     if weapon.Data:
  186.                         
  187.                         try:
  188.                             weapon.Data.Start_Weapon_Special(EntityName, EventName)
  189.                         except AttributeError:
  190.                             pass
  191.  
  192.                     
  193.                 
  194.             
  195.         
  196.     
  197.  
  198.  
  199. def Stop_Weapon_Special(EntityName, EventName):
  200.     me = Bladex.GetEntity(EntityName)
  201.     if me:
  202.         inv = me.GetInventory()
  203.         if inv:
  204.             weapon_name = inv.GetActiveWeapon()
  205.             if weapon_name:
  206.                 weapon = Bladex.GetEntity(weapon_name)
  207.                 if weapon:
  208.                     if weapon.Data:
  209.                         
  210.                         try:
  211.                             weapon.Data.Stop_Weapon_Special(EntityName, EventName)
  212.                         except AttributeError:
  213.                             pass
  214.  
  215.                     
  216.                 
  217.             
  218.         
  219.     
  220.  
  221.  
  222. def Start_Trail(EntityName, EventName):
  223.     me = Bladex.GetEntity(EntityName)
  224.     if me:
  225.         inv = me.GetInventory()
  226.         if inv:
  227.             weapon_name = inv.GetActiveWeapon()
  228.             if weapon_name:
  229.                 weapon = Bladex.GetEntity(weapon_name)
  230.                 if weapon:
  231.                     weapon.MessageEvent(Reference.MESSAGE_START_TRAIL, 0, 0)
  232.                 
  233.             
  234.         
  235.     
  236.  
  237.  
  238. def Stop_Trail(EntityName, EventName):
  239.     me = Bladex.GetEntity(EntityName)
  240.     if me:
  241.         inv = me.GetInventory()
  242.         if inv:
  243.             weapon_name = inv.GetActiveWeapon()
  244.             if weapon_name:
  245.                 weapon = Bladex.GetEntity(weapon_name)
  246.                 if weapon:
  247.                     weapon.MessageEvent(Reference.MESSAGE_STOP_TRAIL, 0, 0)
  248.                 
  249.             
  250.         
  251.     
  252.  
  253.  
  254. def GraspString(EntityName, EventName):
  255.     me = Bladex.GetEntity(EntityName)
  256.     if me:
  257.         inv = me.GetInventory()
  258.         if inv:
  259.             if inv.HoldingBow:
  260.                 bow = Bladex.GetEntity(inv.GetBow())
  261.                 
  262.                 try:
  263.                     bow.Data.GraspString()
  264.                 except AttributeError:
  265.                     print "No string on bow. Do ItemTypes.ItemDefaultFuncs(Bladex.GetEntity('" + bow.Name + "'))"
  266.  
  267.             
  268.         
  269.     
  270.  
  271.  
  272. def UnGraspString(EntityName, EventName):
  273.     me = Bladex.GetEntity(EntityName)
  274.     if me:
  275.         inv = me.GetInventory()
  276.         if inv:
  277.             if inv.HoldingBow:
  278.                 bow = Bladex.GetEntity(inv.GetBow())
  279.                 
  280.                 try:
  281.                     bow.Data.UnGraspString()
  282.                 except AttributeError:
  283.                     print "No string on bow. Do ItemTypes.ItemDefaultFuncs(Bladex.GetEntity('" + bow.Name + "'))"
  284.  
  285.             
  286.         
  287.     
  288.  
  289.  
  290. def AddQuiver(inv, new_quiver_name):
  291.     new_quiver = Bladex.GetEntity(new_quiver_name)
  292.     for i in range(inv.nQuivers):
  293.         quiver_name = inv.GetQuiver(i)
  294.         quiver = Bladex.GetEntity(quiver_name)
  295.         if quiver.Data.ArrowType == new_quiver.Data.ArrowType:
  296.             inv.SetCurrentQuiver(quiver_name)
  297.             quiver.Data.ReceiveArrows(new_quiver.Data.NumberOfArrows(), inv.Owner)
  298.             new_quiver.SubscribeToList('Pin')
  299.             inv.LinkRightHand('None')
  300.             return None
  301.         
  302.     
  303.     inv.AddQuiver(new_quiver_name)
  304.     inv.SetCurrentQuiver(new_quiver_name)
  305.     inv.LinkRightHand('None')
  306.     if inv.HoldingBow:
  307.         inv.LinkRightBack(new_quiver_name)
  308.     
  309.  
  310.  
  311. def ExtendedTakeObject(inv, Object2TakeName):
  312.     o = Bladex.GetEntity(Object2TakeName)
  313.     if o.Kind in Reference.StackObjects.keys():
  314.         inv.AddObject(Object2TakeName, Reference.StackObjects[o.Kind] - 1)
  315.     else:
  316.         inv.AddObject(Object2TakeName, 0)
  317.  
  318.  
  319. def TakeObject(EntityName, Object2TakeName, force_take = TRUE):
  320.     me = Bladex.GetEntity(EntityName)
  321.     inv = me.GetInventory()
  322.     if IsOneTooMany(EntityName, Object2TakeName):
  323.         if force_take:
  324.             DropToMakeRoomFor(EntityName, Object2TakeName)
  325.         else:
  326.             print EntityName + ': Too many objects of this type: ' + Object2TakeName
  327.             return None
  328.     
  329.     object_flag = Reference.GiveObjectFlag(Object2TakeName)
  330.     
  331.     try:
  332.         me.Data.RegisterObjectAsTaken(Object2TakeName)
  333.     except:
  334.         if EntityName == 'Player1':
  335.             print Object2TakeName + ' not registered as taken, Players Data class not created yet'
  336.         
  337.  
  338.     if object_flag == Reference.OBJ_ITEM:
  339.         ExtendedTakeObject(inv, Object2TakeName)
  340.     elif object_flag == Reference.OBJ_SHIELD:
  341.         inv.AddShield(Object2TakeName)
  342.         if not (me.InvLeftBack) and not (me.InvRightBack) and not (me.InvLeft):
  343.             inv.LinkLeftHand(Object2TakeName)
  344.         
  345.     elif object_flag == Reference.OBJ_WEAPON:
  346.         flag = Reference.GiveWeaponFlag(Object2TakeName)
  347.         inv.AddWeapon(Object2TakeName, flag)
  348.         if me.InvLeftBack == '' and me.InvRightBack == '' and me.InvRight == '':
  349.             inv.LinkRightHand(Object2TakeName)
  350.         
  351.     elif object_flag == Reference.OBJ_BOW:
  352.         inv.AddBow(Object2TakeName)
  353.         if not (me.InvLeftBack) and not (me.InvRightBack) and not (me.InvRight) and not (me.InvLeft):
  354.             inv.LinkLeftHand(Object2TakeName)
  355.         
  356.     elif object_flag == Reference.OBJ_QUIVER:
  357.         AddQuiver(inv, Object2TakeName)
  358.     elif object_flag == Reference.OBJ_STANDARD:
  359.         if not (me.InvLeftBack) and not (me.InvRightBack) and not (me.InvRight):
  360.             inv.LinkRightHand(Object2TakeName)
  361.         
  362.     elif object_flag == Reference.OBJ_KEY:
  363.         inv.AddKey(Object2TakeName)
  364.     elif object_flag == Reference.OBJ_SPECIALKEY:
  365.         inv.AddSpecialKey(Object2TakeName)
  366.     elif object_flag == Reference.OBJ_TABLET:
  367.         inv.AddTablet(Object2TakeName)
  368.     elif object_flag == Reference.OBJ_ARROW:
  369.         pass
  370.     elif object_flag == Reference.OBJ_USEME and EntityName != 'Player1':
  371.         ExtendedTakeObject(inv, Object2TakeName)
  372.     else:
  373.         print 'ERROR adding an object to a character !!!'
  374.         print 'Not classified properly in Reference.py!!!'
  375.  
  376.  
  377. def StatR(EntityName):
  378.     me = Bladex.GetEntity(EntityName)
  379.     ObjectName = me.InvRight
  380.     if ObjectName == 'None' or not ObjectName:
  381.         return RA_NO_WEAPON
  382.     
  383.     object_flag = Reference.GiveObjectFlag(ObjectName)
  384.     if object_flag == Reference.OBJ_BOW:
  385.         return RA_BOW
  386.     else:
  387.         return RA_1H_WEAPON
  388.  
  389.  
  390. def StatL(EntityName):
  391.     me = Bladex.GetEntity(EntityName)
  392.     ObjectName = me.InvLeft
  393.     if ObjectName == 'None' or not ObjectName:
  394.         return LA_NO_WEAPON
  395.     
  396.     object_flag = Reference.GiveObjectFlag(ObjectName)
  397.     if object_flag == Reference.OBJ_SHIELD:
  398.         return LA_SHIELD
  399.     elif object_flag == Reference.OBJ_BOW:
  400.         return LA_BOW
  401.     else:
  402.         print 'ERROR - Invalid object in left hand!!!'
  403.         print 'Check it in Reference.py!!!'
  404.         return None
  405.  
  406.  
  407. def IsRightHandStandardObject(EntityName):
  408.     me = Bladex.GetEntity(EntityName)
  409.     if not (me.InvRight):
  410.         return FALSE
  411.     
  412.     object_flag = Reference.GiveObjectFlag(me.InvRight)
  413.     return object_flag == Reference.OBJ_STANDARD
  414.  
  415.  
  416. def IsRightHandWeaponObject(EntityName):
  417.     me = Bladex.GetEntity(EntityName)
  418.     if not (me.InvRight):
  419.         return FALSE
  420.     
  421.     object_flag = Reference.GiveObjectFlag(me.InvRight)
  422.     if not object_flag == Reference.OBJ_WEAPON:
  423.         pass
  424.     return object_flag == Reference.OBJ_BOW
  425.  
  426.  
  427. def IsRightHandAutomaticObject(EntityName):
  428.     me = Bladex.GetEntity(EntityName)
  429.     if not (me.InvRight):
  430.         return FALSE
  431.     
  432.     object_flag = Reference.GiveObjectFlag(me.InvRight)
  433.     return object_flag == Reference.OBJ_USEME
  434.  
  435.  
  436. def IsBehindEntity(MyName, OtherName):
  437.     them = Bladex.GetEntity(OtherName)
  438.     angle1 = them.Angle
  439.     angle2 = B3DLib.GetEntity2EntityAngle(OtherName, MyName)
  440.     return abs(B3DLib.DiffAngle(angle1, angle2)) >= BEHINDANGLE
  441.  
  442.  
  443. def IsFacingEntity(MyName, OtherName):
  444.     me = Bladex.GetEntity(MyName)
  445.     angle1 = me.Angle
  446.     angle2 = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  447.     return abs(B3DLib.DiffAngle(angle1, angle2)) <= FACINGANGLE
  448.  
  449.  
  450. def IsFacingPos(MyName, x, z):
  451.     me = Bladex.GetEntity(MyName)
  452.     angle1 = me.Angle
  453.     p1 = me.Position
  454.     x = x - p1[0]
  455.     z = z - p1[2]
  456.     angle2 = B3DLib.GetXZAngle(x, 0.0, z)
  457.     return abs(B3DLib.DiffAngle(angle1, angle2)) <= FACINGANGLE
  458.  
  459.  
  460. def Turn180(MyName):
  461.     me = Bladex.GetEntity(MyName)
  462.     angle = me.Angle + PI
  463.     if angle >= TWOPI:
  464.         angle = angle - TWOPI
  465.     
  466.     me.Face(angle)
  467.  
  468.  
  469. def QuickTurn180(MyName):
  470.     me = Bladex.GetEntity(MyName)
  471.     angle = me.Angle + PI
  472.     if angle >= TWOPI:
  473.         angle = angle - TWOPI
  474.     
  475.     me.QuickFace(angle)
  476.  
  477.  
  478. def TurnToFaceEntity(MyName, OtherName):
  479.     me = Bladex.GetEntity(MyName)
  480.     angle = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  481.     me.Face(angle)
  482.  
  483.  
  484. def TurnToFaceEntityNow(MyName, OtherName):
  485.     me = Bladex.GetEntity(MyName)
  486.     angle = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  487.     me.Angle = angle
  488.  
  489.  
  490. def QuickTurnToFaceEntity(MyName, OtherName):
  491.     me = Bladex.GetEntity(MyName)
  492.     angle = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  493.     me.QuickFace(angle)
  494.  
  495.  
  496. def TurnToFacePos(MyName, x, z):
  497.     me = Bladex.GetEntity(MyName)
  498.     p1 = me.Position
  499.     x = x - p1[0]
  500.     z = z - p1[2]
  501.     angle = B3DLib.GetXZAngle(x, 0.0, z)
  502.     me.Face(angle)
  503.  
  504.  
  505. def QuickTurnToFacePos(MyName, x, z):
  506.     me = Bladex.GetEntity(MyName)
  507.     p1 = me.Position
  508.     x = x - p1[0]
  509.     z = z - p1[2]
  510.     angle = B3DLib.GetXZAngle(x, 0.0, z)
  511.     me.QuickFace(angle)
  512.  
  513. USE_FROM_INV = 0
  514. USE_FROM_NEARBY = 2
  515. USE_FROM_TAKE = 4
  516.  
  517. def StdUse(EntityName):
  518.     me = Bladex.GetEntity(EntityName)
  519.     if me.Wuea == Reference.WUEA_ENDED:
  520.         return FALSE
  521.     
  522.     if me.Wuea == Reference.WUEA_WAIT:
  523.         return FALSE
  524.     
  525.     if me.AnmEndedFunc:
  526.         return FALSE
  527.     
  528.     TryWithAnother = 1
  529.     if me.Name[0:6] == 'Player' and me.Data.InventoryActive:
  530.         inv = me.GetInventory()
  531.         object_name = inv.GetSelectedObject()
  532.         if object_name:
  533.             object = Bladex.GetEntity(object_name)
  534.             if object and object.CanUse:
  535.                 me.Data.obj_used = object
  536.                 InitDataField.Initialise(object)
  537.                 object.Data.UsedBy = EntityName
  538.                 object.UseFunc(object_name, USE_FROM_INV)
  539.                 TryWithAnother = 0
  540.             
  541.         
  542.     
  543.     if TryWithAnother:
  544.         if me.Data and me.Data.selected_entity:
  545.             if IsValidForUsing(me.Data.selected_entity[0], EntityName):
  546.                 object_flag = Reference.GiveObjectFlag(me.Data.selected_entity[0])
  547.                 if object_flag != Reference.OBJ_USEME and object_flag != Reference.OBJ_ITEM:
  548.                     object = Bladex.GetEntity(me.Data.selected_entity[0])
  549.                     me.Data.obj_used = object
  550.                     InitDataField.Initialise(object)
  551.                     object.Data.UsedBy = EntityName
  552.                     object.UseFunc(object.Name, USE_FROM_NEARBY)
  553.                     return None
  554.                 
  555.             
  556.             if IsValidForTaking(me.Data.selected_entity[0]):
  557.                 me.Data.toggle4t_clearback = FALSE
  558.                 me.Data.stuff_onback_b4 = SthOnBack(EntityName)
  559.                 if TryToTake(EntityName, me.Data.selected_entity[0]):
  560.                     return None
  561.                 
  562.             else:
  563.                 ReportMsg('The selected object cannot be taken')
  564.         else:
  565.             ReportMsg('Nothing selected')
  566.     
  567.  
  568.  
  569. def IsValidForUsing(instance_name, EntityName):
  570.     me = Bladex.GetEntity(EntityName)
  571.     object = Bladex.GetEntity(instance_name)
  572.     if not me and not object and not (object.CanUse) or not (object.UseFunc):
  573.         return FALSE
  574.     
  575.     dist = B3DLib.GetXZDistance(EntityName, instance_name)
  576.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  577.     if dist > chartype.Reach * 1.5:
  578.         return FALSE
  579.     
  580.     heightdiff = -(object.Position[1] - (me.Position[1] + me.Dist2Floor))
  581.     if heightdiff < chartype.MinTake:
  582.         return FALSE
  583.     
  584.     if heightdiff > chartype.MaxTake5:
  585.         return FALSE
  586.     
  587.     return TRUE
  588.  
  589.  
  590. def has_torch(EntityName):
  591.     me = Bladex.GetEntity(EntityName)
  592.     obj_name = me.InvRight
  593.     if obj_name:
  594.         obj = Bladex.GetEntity(obj_name)
  595.         if obj:
  596.             return obj.Kind == 'Antorcha'
  597.         
  598.     
  599.     return 0
  600.  
  601.  
  602. def DestroyBurningItem(EntityName, DestroyTime):
  603.     obj = Bladex.GetEntity(EntityName)
  604.     if obj:
  605.         
  606.         try:
  607.             if not (obj.Data.brkobjdata):
  608.                 Breakings.SetBreakable(EntityName, DestroyTime, DestroyTime)
  609.         except:
  610.             Breakings.SetBreakable(EntityName, DestroyTime, DestroyTime)
  611.  
  612.         brkobj = obj.Data.brkobjdata
  613.         Breakings.ExplodeSpecialObject(EntityName, 3500.0)
  614.     
  615.     for n in brkobj.n_piezas:
  616.         brkobj.pieza[n].CatchOnFire(0.0, 0.0, 0.0)
  617.     
  618.  
  619.  
  620. def StdSetFireToUseFunc(ObjectName, use_from):
  621.     object = Bladex.GetEntity(ObjectName)
  622.     from_pos = (0.0, 0.0, 0.0)
  623.     if use_from == USE_FROM_INV and use_from == USE_FROM_NEARBY or use_from == USE_FROM_TAKE:
  624.         EntityName = object.Data.UsedBy
  625.         me = Bladex.GetEntity(EntityName)
  626.         if me:
  627.             if not has_torch(EntityName):
  628.                 return None
  629.             
  630.             torch = Bladex.GetEntity(me.InvRight)
  631.             if torch.Data.torchobjdata.LightStatus == Torchs.OFF:
  632.                 return None
  633.             
  634.             object.UseFunc = 0
  635.             object.Data.UsedBy = me.InvRight
  636.             QuickTurnToFaceEntity(EntityName, ObjectName)
  637.             heightdiff = -(object.Position[1] - (me.Position[1] + me.Dist2Floor))
  638.             chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  639.             me.AddAnmEventFunc('SetAlightEvent', SetAlightEventHandler)
  640.             if heightdiff <= chartype.MaxTake1:
  641.                 me.LaunchAnmType('fire_g')
  642.             elif heightdiff <= chartype.MaxTake2:
  643.                 me.LaunchAnmType('fire0')
  644.             elif heightdiff <= chartype.MaxTake3:
  645.                 me.LaunchAnmType('fire1')
  646.             elif heightdiff <= chartype.MaxTake4:
  647.                 me.LaunchAnmType('fire2')
  648.             elif heightdiff <= chartype.MaxTake5:
  649.                 me.LaunchAnmType('fire3')
  650.             
  651.         
  652.     
  653.  
  654.  
  655. def SetAlight(ObjectName):
  656.     object = Bladex.GetEntity(ObjectName)
  657.     if object:
  658.         
  659.         try:
  660.             UserName = object.Data.UsedBy
  661.             user = Bladex.GetEntity(UserName)
  662.             user_pos = user.Position
  663.         except:
  664.             user_pos = (0.0, 0.0, 0.0)
  665.  
  666.         object.CatchOnFire(user_pos[0], user_pos[1], user_pos[2])
  667.         if object.Data.BurnTime:
  668.             Bladex.AddScheduledFunc(Bladex.GetTime() + object.Data.BurnTime, DestroyBurningItem, (ObjectName, object.Data.DestroyTime), 'SetAlight' + ObjectName)
  669.         
  670.     
  671.  
  672.  
  673. def SetBurnable(EntityName, BurnTime, DestroyTime):
  674.     object = Bladex.GetEntity(EntityName)
  675.     object.UseFunc = StdSetFireToUseFunc
  676.     InitDataField.Initialise(object)
  677.     object.Data.BurnTime = BurnTime
  678.     object.Data.DestroyTime = DestroyTime
  679.  
  680.  
  681. def SetAlightEventHandler(EntityName, EventName):
  682.     me = Bladex.GetEntity(EntityName)
  683.     me.DelAnmEventFunc(EventName)
  684.     if EventName != 'SetAlightEvent':
  685.         return None
  686.     
  687.     object = me.Data.obj_used
  688.     if object:
  689.         SetAlight(object.Name)
  690.     
  691.  
  692.  
  693. def IsValidForTaking(instance_name):
  694.     object = Bladex.GetEntity(instance_name)
  695.     if object:
  696.         if object.Static and object.Weapon and object.WeaponMode == Reference.ACTIVE_WEAPON_MODE:
  697.             return FALSE
  698.         
  699.         if object.Parent:
  700.             parent = Bladex.GetEntity(object.Parent)
  701.             if parent and parent.Person:
  702.                 return FALSE
  703.             
  704.         
  705.         object_data = None
  706.         if Reference.EntitiesObjectData.has_key(instance_name):
  707.             object_data = Reference.EntitiesObjectData[instance_name]
  708.         elif Reference.DefaultObjectData.has_key(object.Kind):
  709.             object_data = Reference.DefaultObjectData[object.Kind]
  710.         
  711.         if not object_data:
  712.             return FALSE
  713.         
  714.         if object_data[0] == Reference.OBJ_USEME and not (object.CanUse):
  715.             return FALSE
  716.         
  717.     
  718.     return TRUE
  719.  
  720.  
  721. def IsValidForThrowing(object_name):
  722.     object = Bladex.GetEntity(object_name)
  723.     if object:
  724.         if Reference.EntitiesObjectData.has_key(object_name):
  725.             object_data = Reference.EntitiesObjectData[object_name]
  726.         elif Reference.DefaultObjectData.has_key(object.Kind):
  727.             object_data = Reference.DefaultObjectData[object.Kind]
  728.         else:
  729.             return FALSE
  730.         object_flag = object_data[0]
  731.         if object_flag == Reference.OBJ_WEAPON and object_flag == Reference.OBJ_BOW or object_flag == Reference.OBJ_STANDARD:
  732.             return TRUE
  733.         
  734.     
  735.     return FALSE
  736.  
  737.  
  738. def IsValidForDropping(ObjectName):
  739.     if Reference.EntitiesObjectData.has_key(ObjectName):
  740.         object_data = Reference.EntitiesObjectData[ObjectName]
  741.     else:
  742.         object = Bladex.GetEntity(ObjectName)
  743.         if not Reference.DefaultObjectData.has_key(object.Kind):
  744.             return TRUE
  745.         
  746.         object_data = Reference.DefaultObjectData[object.Kind]
  747.     object_flag = object_data[0]
  748.     if object_flag == Reference.OBJ_KEY:
  749.         return FALSE
  750.     elif object_flag == Reference.OBJ_SPECIALKEY:
  751.         return FALSE
  752.     elif object_flag == Reference.OBJ_TABLET:
  753.         return FALSE
  754.     elif object_flag == Reference.OBJ_ITEM:
  755.         return FALSE
  756.     else:
  757.         return TRUE
  758.  
  759.  
  760. def GetCheckSelected(func, Data):
  761.     if Data:
  762.         if Data.selected_entity:
  763.             s = Data.selected_entity[0]
  764.             if func(s):
  765.                 return s
  766.             
  767.         
  768.     
  769.     return None
  770.  
  771.  
  772. def DropToMakeRoomFor(EntityName, ObjectName):
  773.     me = Bladex.GetEntity(EntityName)
  774.     object_flag = Reference.GiveObjectFlag(ObjectName)
  775.     inv = me.GetInventory()
  776.     DropObjectName = None
  777.     if object_flag == Reference.OBJ_ARMOUR:
  778.         print 'Warning DropToMakeRoomFor() unimplimented for Armour...'
  779.     elif object_flag == Reference.OBJ_ITEM:
  780.         ObjectKind = Bladex.GetEntity(ObjectName).Kind
  781.         for i in range(inv.nObjects):
  782.             auxname = inv.GetObject(i)
  783.             if auxname:
  784.                 if Bladex.GetEntity(auxname).Kind == ObjectKind:
  785.                     DropObjectName = auxname
  786.                     break
  787.                 
  788.             else:
  789.                 break
  790.         
  791.     elif object_flag == Reference.OBJ_SHIELD:
  792.         DropObjectName = inv.GetShield(0)
  793.     elif object_flag == Reference.OBJ_WEAPON:
  794.         DropObjectName = inv.GetWeapon(0)
  795.     elif object_flag == Reference.OBJ_BOW:
  796.         if inv.HasBow:
  797.             DropObjectName = inv.GetBow()
  798.         else:
  799.             DropObjectName = inv.GetWeapon(0)
  800.     elif object_flag == Reference.OBJ_QUIVER:
  801.         DropObjectName = inv.GetQuiver(0)
  802.     elif object_flag == Reference.OBJ_STANDARD:
  803.         DropObjectName = me.InvRight
  804.     elif object_flag == Reference.OBJ_KEY:
  805.         print 'Warning DropToMakeRoomFor() unimplimented for Keys...'
  806.     elif object_flag == Reference.OBJ_SPECIALKEY:
  807.         print 'Warning DropToMakeRoomFor() unimplimented for Special Keys...'
  808.     elif object_flag == Reference.OBJ_TABLET:
  809.         print 'Warning DropToMakeRoomFor() unimplimented for Tablets...'
  810.     elif object_flag == Reference.OBJ_USEME:
  811.         DropObjectName = me.InvRight
  812.     elif object_flag == Reference.OBJ_ARROW:
  813.         print 'Warning DropToMakeRoomFor() unimplimented for Arrows...'
  814.     
  815.     if DropObjectName:
  816.         object = Bladex.GetEntity(DropObjectName)
  817.         if object:
  818.             RemoveFromInventory(me, object, 'DropToMakeRoomFor ' + ObjectName)
  819.             object.Position = me.Position
  820.             object.ExcludeHitFor(me)
  821.             if object.TestHit:
  822.                 object.RemoveFromWorld()
  823.             else:
  824.                 object.Alpha = 1.0
  825.                 object.Impulse(0.0, 0.0, 0.0)
  826.         
  827.     
  828.  
  829.  
  830. def IsOneTooMany(EntityName, ObjectName):
  831.     me = Bladex.GetEntity(EntityName)
  832.     if Reference.EntitiesObjectData.has_key(ObjectName):
  833.         object_data = Reference.EntitiesObjectData[ObjectName]
  834.     else:
  835.         object = Bladex.GetEntity(ObjectName)
  836.         object_data = Reference.DefaultObjectData[object.Kind]
  837.     object_flag = object_data[0]
  838.     ret_val = FALSE
  839.     inv = me.GetInventory()
  840.     if object_flag == Reference.OBJ_ITEM:
  841.         ret_val = inv.nObjects >= inv.maxObjects
  842.         if not ret_val:
  843.             ObjectEntity = Bladex.GetEntity(ObjectName)
  844.             for i in range(inv.nObjects):
  845.                 auxname = inv.GetObject(i)
  846.                 if auxname:
  847.                     if Bladex.GetEntity(auxname).Kind == ObjectEntity.Kind:
  848.                         ret_val = inv.GetMaxNumberObjectsAt(i) <= inv.GetNumberObjectsAt(i)
  849.                         break
  850.                     
  851.                 else:
  852.                     break
  853.             
  854.         
  855.     elif object_flag == Reference.OBJ_SHIELD:
  856.         ret_val = inv.nShields >= inv.maxShields
  857.     elif object_flag == Reference.OBJ_WEAPON:
  858.         ret_val = inv.nWeapons >= inv.maxWeapons
  859.     elif object_flag == Reference.OBJ_BOW:
  860.         if not inv.nWeapons >= inv.maxWeapons:
  861.             pass
  862.         ret_val = inv.HasBow
  863.     elif object_flag == Reference.OBJ_QUIVER:
  864.         ret_val = inv.nObjects >= inv.maxObjects
  865.     elif object_flag == Reference.OBJ_STANDARD:
  866.         ret_val = FALSE
  867.     elif object_flag == Reference.OBJ_KEY:
  868.         ret_val = FALSE
  869.     elif object_flag == Reference.OBJ_SPECIALKEY:
  870.         ret_val = FALSE
  871.     elif object_flag == Reference.OBJ_TABLET:
  872.         ret_val = FALSE
  873.     elif object_flag == Reference.OBJ_USEME:
  874.         ret_val = FALSE
  875.     elif object_flag == Reference.OBJ_ARROW:
  876.         ret_val = not CouldSheatheArrow(inv, ObjectName)
  877.     
  878.     return ret_val
  879.  
  880.  
  881. def TryToTake(EntityName, ObjectName):
  882.     me = Bladex.GetEntity(EntityName)
  883.     if me.Wuea == Reference.WUEA_ENDED:
  884.         return FALSE
  885.     
  886.     if me.Wuea == Reference.WUEA_WAIT:
  887.         return FALSE
  888.     
  889.     if me.AnmEndedFunc:
  890.         return FALSE
  891.     
  892.     inv = me.GetInventory()
  893.     if inv.CarringObject(ObjectName):
  894.         return FALSE
  895.     
  896.     object = Bladex.GetEntity(ObjectName)
  897.     dist = B3DLib.GetXZDistance(EntityName, ObjectName)
  898.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  899.     if dist > chartype.Reach:
  900.         ReportMsg('Not in reach')
  901.         return FALSE
  902.     
  903.     me.Data.last_heightdiff = -(object.Position[1] - (me.Position[1] + me.Dist2Floor))
  904.     if me.Data.last_heightdiff < chartype.MinTake:
  905.         ReportMsg('Too low to pick up')
  906.         return FALSE
  907.     elif me.Data.last_heightdiff > chartype.MaxTake5:
  908.         ReportMsg('Too high to pick up')
  909.         return FALSE
  910.     elif IsOneTooMany(EntityName, ObjectName):
  911.         ReportMsg('Too many objects of this type')
  912.         return FALSE
  913.     
  914.     for f in TryToTakeCallBacks:
  915.         pass
  916.     
  917.     QuickTurnToFaceEntity(EntityName, ObjectName)
  918.     me.Data.pickup_entity = ObjectName
  919.     IntermediateTake(EntityName, ObjectName)
  920.     return TRUE
  921.  
  922.  
  923. def UnSheatheArrow(inv):
  924.     des_quiver_name = inv.GetSelectedQuiver()
  925.     inv.LinkRightHand('None')
  926.     if des_quiver_name:
  927.         inv.SetCurrentQuiver(des_quiver_name)
  928.         inv.LinkRightBack('None')
  929.         inv.LinkRightBack(des_quiver_name)
  930.         quiver = Bladex.GetEntity(des_quiver_name)
  931.         if quiver and quiver.Data.NumberOfArrows() > 0:
  932.             arrow = quiver.Data.GiveArrow()
  933.             if arrow:
  934.                 inv.LinkRightHand(arrow.Name)
  935.                 return None
  936.             
  937.         
  938.     
  939.     ReportMsg('Out of Arrows')
  940.  
  941.  
  942. def CouldSheatheArrow(inv, ArrowName):
  943.     arrow = Bladex.GetEntity(ArrowName)
  944.     for i in range(inv.nQuivers):
  945.         quiver_name = inv.GetQuiver(i)
  946.         quiver = Bladex.GetEntity(quiver_name)
  947.     
  948.     return TRUE
  949.  
  950.  
  951. def SheatheArrow(inv, ArrowName):
  952.     UnGraspString(inv.Owner, 'UnGraspString')
  953.     arrow = Bladex.GetEntity(ArrowName)
  954.     for i in range(inv.nQuivers):
  955.         quiver_name = inv.GetQuiver(i)
  956.         quiver = Bladex.GetEntity(quiver_name)
  957.     
  958.     new_quiver_type = Reference.GiveQuiverType(arrow.Kind)
  959.     if new_quiver_type:
  960.         new_quiver = Bladex.CreateEntity(new_quiver_type + '_for_' + inv.Owner, new_quiver_type + '_E', 0, 0, 0, 'Physic')
  961.         ItemTypes.ItemDefaultFuncs(new_quiver)
  962.         inv.AddQuiver(new_quiver.Name)
  963.         inv.SetCurrentQuiver(new_quiver.Name)
  964.         if inv.HoldingBow:
  965.             inv.LinkRightBack(new_quiver.Name)
  966.         
  967.         new_quiver.Data.SetNumberOfArrows(0, inv.Owner)
  968.         if new_quiver.Data.ReceiveArrow(arrow, inv.Owner):
  969.             inv.LinkRightHand('None')
  970.             return None
  971.         
  972.     
  973.     DropReleaseEventHandler(inv.Owner, 'DropRightEvent', FALSE)
  974.  
  975.  
  976. def Toggle4TakingEvent(pj_name, event):
  977.     me = Bladex.GetEntity(pj_name)
  978.     inv = me.GetInventory()
  979.     me.DelAnmEventFunc(event)
  980.     if inv.HoldingBow:
  981.         if me.InvRight:
  982.             if Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  983.                 SheatheArrow(inv, me.InvRight)
  984.             
  985.         else:
  986.             UnSheatheArrow(inv)
  987.     elif me.InvRightBack and Reference.GiveObjectFlag(me.InvRightBack) != Reference.OBJ_QUIVER:
  988.         if not (me.Data.stuff_onback_b4) and me.Data.toggle4t_clearback:
  989.             tmpr_back = me.InvRightBack
  990.             inv.LinkRightBack('None')
  991.             inv.LinkRightHand(tmpr_back)
  992.         else:
  993.             inv.LinkRightHand('None')
  994.     elif me.InvRight and not (me.Data.toggle4t_clearback):
  995.         inv.LinkRightBack(me.InvRight)
  996.     
  997.     inv.LinkRightHand('None')
  998.     if me.Data.toggle4t_clearback:
  999.         me.Data.toggle4t_clearback = FALSE
  1000.         if me.InvLeftBack and Reference.GiveObjectFlag(me.InvLeftBack) == Reference.OBJ_BOW:
  1001.             ToggleWEvent(pj_name, event)
  1002.         
  1003.     
  1004.  
  1005.  
  1006. def ToggleRight4Taking(EntityName):
  1007.     me = Bladex.GetEntity(EntityName)
  1008.     if IsRightHandStandardObject(EntityName):
  1009.         if TryDropRight(EntityName):
  1010.             print 'TryDropRight is ok'
  1011.             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  1012.             if me.InvRight:
  1013.                 return FALSE
  1014.             
  1015.         
  1016.         me.Wuea = Reference.WUEA_ENDED
  1017.     
  1018.     if me.InvRight:
  1019.         me.AddAnmEventFunc('ChangeREvent', Toggle4TakingEvent)
  1020.         UnGraspString(EntityName, 'UnGraspString')
  1021.         me.LaunchAnmType('Chg_r')
  1022.     
  1023.     return TRUE
  1024.  
  1025.  
  1026. def IntermediateTake(EntityName, ObjectName):
  1027.     me = Bladex.GetEntity(EntityName)
  1028.     object = Bladex.GetEntity(ObjectName)
  1029.     inv = me.GetInventory()
  1030.     if inv.CarringObject(ObjectName):
  1031.         return None
  1032.     
  1033.     if inv.HoldingBow:
  1034.         UnGraspString(EntityName, 'UnGraspString')
  1035.     
  1036.     if Reference.EntitiesObjectData.has_key(ObjectName):
  1037.         object_data = Reference.EntitiesObjectData[ObjectName]
  1038.     else:
  1039.         object_data = Reference.DefaultObjectData[object.Kind]
  1040.     object_flag = object_data[0]
  1041.     if object_flag == Reference.OBJ_ARMOUR:
  1042.         if me.CharTypeExt != object_data[1]:
  1043.             ReportMsg('Type of armour not for me')
  1044.             print 'Info is ' + str(object_data[1])
  1045.             return None
  1046.         
  1047.         if me.Data.armour_level >= object_data[2]:
  1048.             ReportMsg('Quality of armour not worthy')
  1049.             return None
  1050.         
  1051.         if FreeBothHands(EntityName, None, (), 0):
  1052.             TakeMainAnm(EntityName)
  1053.         else:
  1054.             me.AnmEndedFunc = TakeMainAnm
  1055.     
  1056.     if object_flag == Reference.OBJ_SHIELD:
  1057.         if me.InvRight:
  1058.             if ToggleRight4Taking(EntityName) == FALSE:
  1059.                 return None
  1060.             
  1061.             me.AnmEndedFunc = TakeMainAnm
  1062.         else:
  1063.             TakeMainAnm(EntityName)
  1064.     elif object_flag == Reference.OBJ_BOW:
  1065.         if me.InvRight:
  1066.             if ToggleRight4Taking(EntityName) == FALSE:
  1067.                 return None
  1068.             
  1069.             me.AnmEndedFunc = TakeMainAnm
  1070.         else:
  1071.             TakeMainAnm(EntityName)
  1072.     elif object_flag == Reference.OBJ_WEAPON:
  1073.         if me.InvRight:
  1074.             if ToggleRight4Taking(EntityName) == FALSE:
  1075.                 return None
  1076.             
  1077.             me.AnmEndedFunc = TakeMainAnm
  1078.         else:
  1079.             w_flag = Reference.GiveWeaponFlag(ObjectName)
  1080.             if me.InvLeft != '' and w_flag != Reference.W_FLAG_1H:
  1081.                 me.AddAnmEventFunc('ChangeLEvent', Left2InvEvent)
  1082.                 me.LaunchAnmType('Chg_l')
  1083.                 me.AnmEndedFunc = TakeMainAnm
  1084.             else:
  1085.                 TakeMainAnm(EntityName)
  1086.     elif object_flag == Reference.OBJ_STANDARD:
  1087.         if inv.HoldingBow:
  1088.             if me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  1089.                 SheatheArrow(inv, me.InvRight)
  1090.             
  1091.             inv.LinkLeftBack(me.InvLeft)
  1092.             inv.LinkLeftHand('None')
  1093.         
  1094.         if me.InvRight:
  1095.             if ToggleRight4Taking(EntityName) == FALSE:
  1096.                 return None
  1097.             
  1098.             me.AnmEndedFunc = TakeMainAnm
  1099.         else:
  1100.             TakeMainAnm(EntityName)
  1101.     elif me.InvRight:
  1102.         if ToggleRight4Taking(EntityName) != FALSE:
  1103.             me.AnmEndedFunc = TakeMainAnm
  1104.         
  1105.     else:
  1106.         TakeMainAnm(EntityName)
  1107.  
  1108.  
  1109. def ToggleAfterTakeObj(EntityName):
  1110.     me = Bladex.GetEntity(EntityName)
  1111.     me.AnmEndedFunc = None
  1112.     inv = me.GetInventory()
  1113.     if IsRightHandStandardObject(EntityName):
  1114.         return None
  1115.     
  1116.     me.Data.toggle4t_clearback = TRUE
  1117.     if me.Data.stuff_onback_b4:
  1118.         if SthOnBack(EntityName):
  1119.             ToggleRight4Taking(EntityName)
  1120.         else:
  1121.             ToggleRight4Taking(EntityName)
  1122.     else:
  1123.         ToggleRight4Taking(EntityName)
  1124.  
  1125.  
  1126. def TakeObject2Inv(EntityName):
  1127.     me = Bladex.GetEntity(EntityName)
  1128.     if not (me.Data) or not (me.Data.pickup_entity):
  1129.         return FALSE
  1130.     
  1131.     object_flag = Reference.GiveObjectFlag(me.Data.pickup_entity)
  1132.     if object_flag == Reference.OBJ_ARROW and me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  1133.         return FALSE
  1134.     
  1135.     back_flag = SthOnBack(EntityName)
  1136.     if back_flag and object_flag == Reference.OBJ_WEAPON:
  1137.         w_flag = Reference.GiveWeaponFlag(me.Data.pickup_entity)
  1138.         if w_flag != Reference.W_FLAG_1H:
  1139.             back_flag = 0
  1140.         
  1141.     
  1142.     weapon_stay = 0
  1143.     if not (me.Data.stuff_onback_b4) and not back_flag and object_flag == Reference.OBJ_WEAPON:
  1144.         if not (me.InvLeft) or Reference.GiveObjectFlag(me.InvLeft) != Reference.OBJ_BOW:
  1145.             weapon_stay = 1
  1146.         
  1147.     
  1148.     if object_flag != Reference.OBJ_STANDARD and object_flag != Reference.OBJ_USEME and not weapon_stay:
  1149.         return TRUE
  1150.     
  1151.     return FALSE
  1152.  
  1153.  
  1154. def TakeObject2Left(EntityName):
  1155.     me = Bladex.GetEntity(EntityName)
  1156.     if me.Data and not (me.Data.pickup_entity == me.InvRight):
  1157.         if me.InvRight:
  1158.             return FALSE
  1159.         
  1160.     
  1161.     if me.Data and me.Data.pickup_entity:
  1162.         if not (me.InvLeft):
  1163.             object_flag = Reference.GiveObjectFlag(me.Data.pickup_entity)
  1164.             if object_flag == Reference.OBJ_SHIELD:
  1165.                 if TwoHandedWeaponOnBack(EntityName):
  1166.                     return FALSE
  1167.                 
  1168.                 if not (me.InvLeftBack):
  1169.                     return TRUE
  1170.                 
  1171.             
  1172.             if object_flag == Reference.OBJ_BOW:
  1173.                 if not (me.InvLeftBack) and not (me.InvRightBack):
  1174.                     return TRUE
  1175.                 
  1176.             
  1177.         
  1178.     
  1179.     return FALSE
  1180.  
  1181.  
  1182. def RemoveRightHandler(EntityName, EventName):
  1183.     me = Bladex.GetEntity(EntityName)
  1184.     me.DelAnmEventFunc(EventName)
  1185.     inv = me.GetInventory()
  1186.     if me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  1187.         SheatheArrow(inv, me.InvRight)
  1188.     else:
  1189.         object_name = me.InvRight
  1190.         inv.LinkRightHand('None')
  1191.         
  1192.         try:
  1193.             if object_name and me.Data.obj2left:
  1194.                 inv.LinkLeftHand(object_name)
  1195.             
  1196.             me.Data.obj2left = None
  1197.         except AttributeError:
  1198.             pass
  1199.  
  1200.  
  1201.  
  1202. def TakeArmour(EntityName):
  1203.     me = Bladex.GetEntity(EntityName)
  1204.     ObjectName = me.Data.pickup_entity
  1205.     object = Bladex.GetEntity(ObjectName)
  1206.     if Reference.EntitiesObjectData.has_key(ObjectName):
  1207.         object_data = Reference.EntitiesObjectData[ObjectName]
  1208.     else:
  1209.         object_data = Reference.DefaultObjectData[object.Kind]
  1210.     if object_data[0] != Reference.OBJ_ARMOUR:
  1211.         print 'ERROR in Actions.TakeArmour , object is not an armour!!!'
  1212.         return None
  1213.     
  1214.     ct = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  1215.     sound = Bladex.CreateSound('..\\..\\Sounds\\cambio-armadura2.wav', EntityName + 'SoundNewArmour')
  1216.     sound.Volume = 0.6
  1217.     sound.MinDistance = 10000
  1218.     sound.MaxDistance = 20000
  1219.     sound.PlayStereo()
  1220.     right = me.InvRight
  1221.     left = me.InvLeft
  1222.     rightback = me.InvRightBack
  1223.     leftback = me.InvLeftBack
  1224.     inv = me.GetInventory()
  1225.     inv.LinkRightHand('')
  1226.     inv.LinkLeftHand('')
  1227.     inv.LinkBack('')
  1228.     me.Data.UnlinkAll(EntityName, '')
  1229.     me.ResetWounds()
  1230.     if object_data[2] == 0:
  1231.         me.SetMesh(ct.NoArmour)
  1232.     elif object_data[2] == 1:
  1233.         me.SetMesh(ct.LowArmour)
  1234.     elif object_data[2] == 2:
  1235.         me.SetMesh(ct.MedArmour)
  1236.     elif object_data[2] == 3:
  1237.         me.SetMesh(ct.HighArmour)
  1238.     else:
  1239.         print 'ERROR in Actions.TakeArmour , armour level!!!'
  1240.     if rightback:
  1241.         inv.LinkRightHand(rightback)
  1242.         inv.LinkRightBack(rightback)
  1243.     
  1244.     if leftback:
  1245.         inv.LinkLeftHand(leftback)
  1246.         inv.LinkLeftBack(leftback)
  1247.     
  1248.     if right:
  1249.         inv.LinkRightHand(right)
  1250.     
  1251.     if left:
  1252.         inv.LinkLeftHand(left)
  1253.     
  1254.     me.Data.armour_level = object_data[2]
  1255.     me.Data.armour_prot_factor = object_data[3]
  1256.     object.SubscribeToList('Pin')
  1257.     me.AnmEndedFunc(EntityName)
  1258.     return None
  1259.  
  1260.  
  1261. def TakeMainAnm(EntityName):
  1262.     me = Bladex.GetEntity(EntityName)
  1263.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  1264.     object_name = me.Data.pickup_entity
  1265.     ret = OnInitTake.OnInitTakeFunc(object_name)
  1266.     if OnInitTake.InitTakeDictionary.has_key(object_name) and not ret:
  1267.         return FALSE
  1268.     
  1269.     if not (me.Data.pickup_entity):
  1270.         return FALSE
  1271.     
  1272.     inv = me.GetInventory()
  1273.     if inv.CarringObject(object_name):
  1274.         return FALSE
  1275.     
  1276.     obj2inv = TakeObject2Inv(EntityName)
  1277.     me.Data.obj2left = TakeObject2Left(EntityName)
  1278.     if Reference.GiveObjectFlag(object_name) == Reference.OBJ_ARMOUR:
  1279.         Bladex.AddScheduledFunc(Bladex.GetTime() + 0.5, AuxFuncs.FadeTo, (0.5, 0.5))
  1280.         Bladex.AddScheduledFunc(Bladex.GetTime() + 1.0, TakeArmour, (EntityName,))
  1281.     elif me.Data.last_heightdiff <= chartype.MaxTake1:
  1282.         if obj2inv:
  1283.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1284.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1285.             me.LaunchAnmType('tke_r_key00')
  1286.         else:
  1287.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1288.             me.LaunchAnmType('tke_r_01')
  1289.     elif me.Data.last_heightdiff <= chartype.MaxTake2:
  1290.         if obj2inv:
  1291.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1292.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1293.             me.LaunchAnmType('tke_r_key01')
  1294.         else:
  1295.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1296.             me.LaunchAnmType('tke_r_02')
  1297.     elif me.Data.last_heightdiff <= chartype.MaxTake3:
  1298.         if obj2inv:
  1299.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1300.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1301.             me.LaunchAnmType('tke_r_key02')
  1302.         else:
  1303.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1304.             me.LaunchAnmType('tke_r_03')
  1305.     elif me.Data.last_heightdiff <= chartype.MaxTake4:
  1306.         if obj2inv:
  1307.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1308.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1309.             me.LaunchAnmType('tke_r_key03')
  1310.         else:
  1311.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1312.             me.LaunchAnmType('tke_r_04')
  1313.     elif me.Data.last_heightdiff <= chartype.MaxTake5:
  1314.         if obj2inv:
  1315.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1316.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1317.             me.LaunchAnmType('tke_r_key04')
  1318.         else:
  1319.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1320.             me.LaunchAnmType('tke_r_05')
  1321.     else:
  1322.         print 'Error in SubTake (last_height_diff) , Actions.py'
  1323.         if obj2inv:
  1324.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1325.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1326.             me.LaunchAnmType('tke_r_key04')
  1327.         else:
  1328.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1329.             me.LaunchAnmType('tke_r_05')
  1330.     if Reference.GiveObjectFlag(object_name) == Reference.OBJ_ARMOUR:
  1331.         return None
  1332.     
  1333.     if obj2inv:
  1334.         me.AnmEndedFunc = TakeStraightRecover
  1335.     else:
  1336.         me.AnmEndedFunc = MainTake2Inv
  1337.     return TRUE
  1338.  
  1339.  
  1340. def TakeStraightRecover(EntityName):
  1341.     me = Bladex.GetEntity(EntityName)
  1342.     me.Data.toggle4t_clearback = TRUE
  1343.     if not (me.Data.stuff_onback_b4) and SthOnBack(EntityName) and me.InvRightBack and Reference.GiveObjectFlag(me.InvRightBack) == Reference.OBJ_QUIVER:
  1344.         me.AddAnmEventFunc('ChangeREvent', Toggle4TakingEvent)
  1345.         UnGraspString(EntityName, 'UnGraspString')
  1346.         me.LaunchAnmType('Chg_r')
  1347.     
  1348.  
  1349.  
  1350. def MainTake2Inv(EntityName):
  1351.     me = Bladex.GetEntity(EntityName)
  1352.     if not (me.Data) or not (me.Data.pickup_entity):
  1353.         return None
  1354.     
  1355.     object_name = me.Data.pickup_entity
  1356.     if IsRightHandStandardObject(EntityName):
  1357.         return None
  1358.     
  1359.     if IsRightHandAutomaticObject(EntityName):
  1360.         return None
  1361.     
  1362.     object_flag = Reference.GiveObjectFlag(object_name)
  1363.     if object_flag == Reference.OBJ_ARROW and me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  1364.         return None
  1365.     
  1366.     if not (me.Data.stuff_onback_b4) and not SthOnBack(EntityName) and IsRightHandWeaponObject(EntityName):
  1367.         return None
  1368.     
  1369.     ToggleAfterTakeObj(EntityName)
  1370.  
  1371.  
  1372. def PickupEventHandler(EntityName, EventName, force_take = TRUE):
  1373.     me = Bladex.GetEntity(EntityName)
  1374.     if EventName != 'PickupEvent':
  1375.         return None
  1376.     
  1377.     if not (me.Data) or not (me.Data.pickup_entity):
  1378.         return None
  1379.     
  1380.     if Bladex.GetEntity(me.Data.pickup_entity) == None:
  1381.         return None
  1382.     
  1383.     object_name = me.Data.pickup_entity
  1384.     dist = B3DLib.GetXZDistance(EntityName, object_name)
  1385.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  1386.     if dist > chartype.Reach:
  1387.         ReportMsg('Not in reach')
  1388.         return FALSE
  1389.     
  1390.     object = Bladex.GetEntity(object_name)
  1391.     if object.Parent:
  1392.         parent = Bladex.GetEntity(object.Parent)
  1393.         if parent.Person:
  1394.             return None
  1395.         
  1396.         parent.Unlink(object)
  1397.     
  1398.     Ontake.OnTakeFunc(object_name)
  1399.     Stars.DeTwinkle(object_name)
  1400.     me.Data.selected_entity = None
  1401.     me.DelAnmEventFunc(EventName)
  1402.     if IsOneTooMany(EntityName, object_name):
  1403.         if force_take:
  1404.             DropToMakeRoomFor(EntityName, object_name)
  1405.         else:
  1406.             print EntityName + ': Too many objects of this type: ' + object_name
  1407.             return None
  1408.     
  1409.     object_flag = Reference.GiveObjectFlag(object_name)
  1410.     inv = me.GetInventory()
  1411.     weapon_added = FALSE
  1412.     if not (me.InvRight):
  1413.         if object_flag == Reference.OBJ_WEAPON:
  1414.             flag = Reference.GiveWeaponFlag(object_name)
  1415.             inv.AddWeapon(object_name, flag)
  1416.             WeaponName = Bladex.GetEntity(object_name).Kind
  1417.             weapon_added = TRUE
  1418.             if netgame.GetNetState() == 0:
  1419.                 if not (me.Data.NPC) and not me.Data.WasObjectAlreadyTaken(object_name):
  1420.                     KnightWeaps = [
  1421.                         'QueenSword',
  1422.                         'IceSword',
  1423.                         'FireSword',
  1424.                         'Gladius',
  1425.                         'Orksword',
  1426.                         'Espadaelfica',
  1427.                         'Espadaromana',
  1428.                         'Espadacurva',
  1429.                         'Dagesse',
  1430.                         'Cimitarra',
  1431.                         'EgyptSword',
  1432.                         'Espadafilo',
  1433.                         'Espada',
  1434.                         'Maza',
  1435.                         'Maza2',
  1436.                         'Maza3']
  1437.                     DwarfWeaps = [
  1438.                         'CrushHammer',
  1439.                         'FireAxe',
  1440.                         'IceHammer',
  1441.                         'Hacha',
  1442.                         'Hacha5',
  1443.                         'Hacha4',
  1444.                         'Hacha3',
  1445.                         'Hacha6',
  1446.                         'Hacha2',
  1447.                         'Garrote',
  1448.                         'Martillo',
  1449.                         'Martillo2',
  1450.                         'Garropin',
  1451.                         'MazaDoble',
  1452.                         'Garrote2',
  1453.                         'Martillo3']
  1454.                     AmazonWeaps = [
  1455.                         'TaiSword',
  1456.                         'SteelFeather',
  1457.                         'FireBo',
  1458.                         'LightEdge',
  1459.                         'Ninjato',
  1460.                         'HookSword',
  1461.                         'Katana',
  1462.                         'DoubleSword',
  1463.                         'Bo',
  1464.                         'Lanza',
  1465.                         'Naginata',
  1466.                         'Tridente',
  1467.                         'Hachacuchilla',
  1468.                         'Naginata2',
  1469.                         'DeathBo',
  1470.                         'CrushBo']
  1471.                     BarbWeaps = [
  1472.                         'FireBigSword',
  1473.                         'IceAxe',
  1474.                         'DalWeapon',
  1475.                         'Sablazo',
  1476.                         'Chaosword',
  1477.                         'DeathSword',
  1478.                         'LongSword',
  1479.                         'Alfanje',
  1480.                         'BigSword',
  1481.                         'SawSword',
  1482.                         'FlatSword',
  1483.                         'Eclipse',
  1484.                         'Guadanya',
  1485.                         'Hacha2hojas',
  1486.                         'RhinoClub',
  1487.                         'Hacharrajada']
  1488.                     char = Bladex.GetEntity('Player1')
  1489.                     import Scorer
  1490.                     if char.Kind == 'Barbarian_N':
  1491.                         if not AmazonWeaps.count(WeaponName) and not DwarfWeaps.count(WeaponName) and not KnightWeaps.count(WeaponName):
  1492.                             Scorer.SlideTBS(0)
  1493.                         
  1494.                     
  1495.                     if char.Kind == 'Amazon_N':
  1496.                         if not BarbWeaps.count(WeaponName) and not DwarfWeaps.count(WeaponName) and not KnightWeaps.count(WeaponName):
  1497.                             Scorer.SlideTBS(0)
  1498.                         
  1499.                     
  1500.                     if char.Kind == 'Dwarf_N':
  1501.                         if not AmazonWeaps.count(WeaponName) and not BarbWeaps.count(WeaponName) and not KnightWeaps.count(WeaponName):
  1502.                             Scorer.SlideTBS(0)
  1503.                         
  1504.                     
  1505.                     if char.Kind == 'Knight_N':
  1506.                         if not AmazonWeaps.count(object_name) and not DwarfWeaps.count(object_name) and not BarbWeaps.count(object_name):
  1507.                             Scorer.SlideTBS(0)
  1508.                         
  1509.                     
  1510.                 
  1511.             
  1512.         
  1513.         inv.LinkRightHand(object_name)
  1514.     
  1515.     if object_flag == Reference.OBJ_ITEM:
  1516.         ExtendedTakeObject(inv, object_name)
  1517.     elif object_flag == Reference.OBJ_SHIELD:
  1518.         inv.AddShield(object_name)
  1519.     elif object_flag == Reference.OBJ_WEAPON:
  1520.         if weapon_added == FALSE:
  1521.             flag = Reference.GiveWeaponFlag(object_name)
  1522.             inv.AddWeapon(object_name, flag)
  1523.             if not (me.Data.NPC) and not me.Data.WasObjectAlreadyTaken(object_name):
  1524.                 import Scorer
  1525.                 Scorer.SlideTBS(0)
  1526.             
  1527.         
  1528.     elif object_flag == Reference.OBJ_BOW:
  1529.         inv.AddBow(object_name)
  1530.     elif object_flag == Reference.OBJ_QUIVER:
  1531.         AddQuiver(inv, object_name)
  1532.     elif object_flag == Reference.OBJ_STANDARD:
  1533.         pass
  1534.     elif object_flag == Reference.OBJ_KEY:
  1535.         inv.AddKey(object_name)
  1536.     elif object_flag == Reference.OBJ_SPECIALKEY:
  1537.         inv.AddSpecialKey(object_name)
  1538.     elif object_flag == Reference.OBJ_TABLET:
  1539.         inv.AddTablet(object_name)
  1540.     elif object_flag == Reference.OBJ_USEME:
  1541.         if IsValidForUsing(object_name, EntityName):
  1542.             me.Data.obj_used = Bladex.GetEntity(object_name)
  1543.             object = Bladex.GetEntity(object_name)
  1544.             object.Data.UsedBy = EntityName
  1545.             object.UseFunc(object_name, USE_FROM_TAKE)
  1546.         
  1547.     elif object_flag == Reference.OBJ_ARROW and not (inv.HoldingBow):
  1548.         pass
  1549.     
  1550.     me.Data.RegisterObjectAsTaken(object_name)
  1551.  
  1552.  
  1553. def ThrowTime2ThrowForce(throw_pressed):
  1554.     curve_f = 3.0
  1555.     if throw_pressed < Reference.THROW_TIME_MIN:
  1556.         MinThrowForce = Reference.THROW_TIME_MIN / Reference.THROW_TIME_MAX
  1557.         MinThrowForce = pow(MinThrowForce, curve_f)
  1558.         ThrowForce = (throw_pressed / Reference.THROW_TIME_MIN) * MinThrowForce
  1559.     elif throw_pressed < Reference.THROW_TIME_MAX:
  1560.         ThrowForce = min(throw_pressed, Reference.THROW_TIME_MAX) / Reference.THROW_TIME_MAX
  1561.         ThrowForce = pow(ThrowForce, curve_f)
  1562.     else:
  1563.         ThrowForce = 1.0
  1564.     return ThrowForce
  1565.  
  1566.  
  1567. def TestThrowRight(EntityName):
  1568.     me = Bladex.GetEntity(EntityName)
  1569.     throw_pressed = Bladex.GetTimeActionHeld('Throw')
  1570.     if not throw_pressed:
  1571.         return None
  1572.     
  1573.     if throw_pressed < Reference.THROW_TIME_MIN:
  1574.         if netgame.GetNetState() != 2:
  1575.             TryDropRight(EntityName)
  1576.         else:
  1577.             netgame.SendUserString(Netval.NET_GAME_THROW_WEAPON, netgame.GetClientId() + ' ' + `-1`)
  1578.     elif netgame.GetNetState() != 2:
  1579.         me.Data.ThrowForce = ThrowTime2ThrowForce(throw_pressed)
  1580.         StdThrowObject(EntityName)
  1581.     else:
  1582.         netgame.SendUserString(Netval.NET_GAME_THROW_WEAPON, netgame.GetClientId() + ' ' + `ThrowTime2ThrowForce(throw_pressed)`)
  1583.  
  1584.  
  1585. def EnterThrowingMode(EntityName):
  1586.     pass
  1587.  
  1588.  
  1589. def TestThrowLeft(EntityName):
  1590.     me = Bladex.GetEntity(EntityName)
  1591.     throw_pressed = Bladex.GetTimeActionHeld('Throw')
  1592.     if not throw_pressed:
  1593.         return None
  1594.     
  1595.     TryDropLeft(EntityName)
  1596.  
  1597.  
  1598. def StdThrowObject(EntityName):
  1599.     me = Bladex.GetEntity(EntityName)
  1600.     statR = StatR(EntityName)
  1601.     if statR != RA_NO_WEAPON and statR != RA_BOW:
  1602.         object = Bladex.GetEntity(me.InvRight)
  1603.         if IsValidForThrowing(object.Name):
  1604.             object.ExcludeHitFor(me)
  1605.             mass = object.Mass
  1606.             if mass <= Reference.LightMassMax:
  1607.                 me.AddAnmEventFunc('ThrowLightFacingEvent', ThrowReleaseEventHandler)
  1608.                 me.LaunchAnmType('1tw_l_f')
  1609.             else:
  1610.                 me.AddAnmEventFunc('ThrowHeavyFacingEvent', ThrowReleaseEventHandler)
  1611.                 me.LaunchAnmType('1tw_h_f')
  1612.         else:
  1613.             ReportMsg('Cannot be thrown')
  1614.             StdDropObject(EntityName)
  1615.     
  1616.  
  1617.  
  1618. def RemoveFromInventory(me, object, EventName):
  1619.     me.Unlink(object)
  1620.     inv = me.GetInventory()
  1621.     object_name = object.Name
  1622.     if object_name == me.InvRight:
  1623.         me.RemoveFromInventRight()
  1624.     
  1625.     if object_name == me.InvLeft:
  1626.         me.RemoveFromInventLeft()
  1627.     
  1628.     object_flag = Reference.GiveObjectFlag(object_name)
  1629.     if object_flag == Reference.OBJ_ITEM:
  1630.         inv.RemoveObject(object_name)
  1631.     elif object_flag == Reference.OBJ_SHIELD:
  1632.         inv.RemoveShield(object_name)
  1633.     elif object_flag == Reference.OBJ_WEAPON:
  1634.         inv.RemoveWeapon(object_name)
  1635.     elif object_flag == Reference.OBJ_BOW:
  1636.         inv.RemoveBow(object_name)
  1637.     elif object_flag == Reference.OBJ_QUIVER:
  1638.         inv.RemoveQuiver(object_name)
  1639.     elif object_flag == Reference.OBJ_STANDARD:
  1640.         pass
  1641.     elif object_flag == Reference.OBJ_KEY:
  1642.         inv.RemoveKey(object_name)
  1643.     elif object_flag == Reference.OBJ_SPECIALKEY:
  1644.         inv.RemoveSpecialKey(object_name)
  1645.     elif object_flag == Reference.OBJ_TABLET:
  1646.         inv.RemoveTablet(object_name)
  1647.     elif object_flag == Reference.OBJ_USEME:
  1648.         pass
  1649.     
  1650.  
  1651.  
  1652. def ThrownWeaponStopFunc(EntityName):
  1653.     object = Bladex.GetEntity(EntityName)
  1654.     if object:
  1655.         object.MessageEvent(MESSAGE_STOP_WEAPON, 0, 0)
  1656.         object.MessageEvent(MESSAGE_STOP_TRAIL, 0, 0)
  1657.         
  1658.         try:
  1659.             if object.Data.PrevHitFunc:
  1660.                 object.HitFunc = object.Data.PrevHitFunc
  1661.                 object.Data.PrevHitFunc = None
  1662.                 object.HitFunc(EntityName)
  1663.         except AttributeError:
  1664.             pass
  1665.  
  1666.     
  1667.  
  1668.  
  1669. def ThrownWeaponInflictHitFunc(EntityName, VictimName, ImpX, ImpY, ImpZ):
  1670.     object = Bladex.GetEntity(EntityName)
  1671.     victim = Bladex.GetEntity(VictimName)
  1672.     print 'Thrown object hitting ' + VictimName
  1673.     object.MessageEvent(MESSAGE_STOP_WEAPON, 0, 0)
  1674.     if object.Data.PrevInflictHitFunc:
  1675.         object.InflictHitFunc = object.Data.PrevInflictHitFunc
  1676.         object.Data.PrevInflictHitFunc = None
  1677.         object.InflictHitFunc(EntityName, VictimName, ImpX, ImpY, ImpZ)
  1678.     else:
  1679.         object.InflictHitFunc = 0
  1680.  
  1681.  
  1682. def AutoCalcThrow(d, h, V, g):
  1683.     g2 = g ** 2
  1684.     V2 = V ** 2
  1685.     V4 = V ** 4
  1686.     d2 = d ** 2
  1687.     d4 = d ** 4
  1688.     a = h ** 2 + d2
  1689.     b = d2 * (-1.0 - h * g / V2)
  1690.     c = 0.25 * g2 * d4 / V4
  1691.     sq_term = b ** 2 - 4 * a * c
  1692.     if sq_term < 0.0:
  1693.         print "Auto calc doesn't reach"
  1694.         return (-PI * 0.25, 2.0)
  1695.     else:
  1696.         sq_term = math.sqrt(sq_term)
  1697.         k = (-b + sq_term) / (2.0 * a)
  1698.         angle = -math.acos(math.sqrt(k))
  1699.         time = d / (V * math.cos(angle))
  1700.         if abs(h - (V * math.sin(angle) * time + 0.5 * g * time * time)) > 0.001:
  1701.             angle = -angle
  1702.             time = d / (V * math.cos(angle))
  1703.         
  1704.         print 'Auto calc gives angle: ' + `angle` + ' with time: ' + `time`
  1705.         return (angle, time)
  1706.  
  1707.  
  1708. def ThrowReleaseEventHandler(EntityName, EventName):
  1709.     me = Bladex.GetEntity(EntityName)
  1710.     if EventName == 'ThrowLeftEvent':
  1711.         print 'LeftThrow'
  1712.         if me.InvLeft == 'None' or not (me.InvLeft):
  1713.             return None
  1714.         
  1715.         object = Bladex.GetEntity(me.InvLeft)
  1716.     elif me.InvRight == 'None' or not (me.InvRight):
  1717.         return None
  1718.     
  1719.     object = Bladex.GetEntity(me.InvRight)
  1720.     
  1721.     try:
  1722.         object.Data.ThrowReleaseEventHandler(me.Name, EventName)
  1723.     except AttributeError:
  1724.         if object.TestHit:
  1725.             return None
  1726.         
  1727.         RemoveFromInventory(me, object, EventName)
  1728.         F = me.Data.ThrowForce * 34000.0
  1729.         if me.InCombat:
  1730.             target = Bladex.GetEntity(me.ActiveEnemy)
  1731.             target_pos = target.Position
  1732.             source_pos = object.Position
  1733.             x = target_pos[0] - source_pos[0]
  1734.             y = target_pos[1] - source_pos[1]
  1735.             z = target_pos[2] - source_pos[2]
  1736.             (angle, time) = AutoCalcThrow(math.sqrt(x * x + z * z), y, F / object.Mass, +9800.0)
  1737.         elif EventName == 'ThrowLightFacingEvent':
  1738.             angle = -PI * 0.0625
  1739.         elif EventName == 'ThrowHeavyFacingEvent':
  1740.             angle = -PI * 0.125
  1741.         else:
  1742.             angle = -PI * 0.0625
  1743.         impulse = me.Rel2AbsVector(0.0, -math.cos(angle) * F, -math.sin(angle) * F)
  1744.         if me.InCombat:
  1745.             angle = B3DLib.Pos2PosXZAngle(source_pos[0], source_pos[1], source_pos[2], target_pos[0], target_pos[1], target_pos[2])
  1746.             diff_angle = min(max(B3DLib.DiffAngle(angle, me.Angle), -FACINGANGLE), FACINGANGLE)
  1747.             (x, y, z) = impulse
  1748.             cos_ang = math.cos(diff_angle)
  1749.             sin_ang = math.sin(diff_angle)
  1750.             impulse = (x * cos_ang - z * sin_ang, y, x * sin_ang + z * cos_ang)
  1751.         
  1752.         object.Impulse(impulse[0], impulse[1], impulse[2])
  1753.         throw_style = Reference.THR_SPINNING
  1754.         if Reference.EntitiesObjectData.has_key(object.Name):
  1755.             if Reference.EntitiesObjectData[object.Name][0] == Reference.OBJ_WEAPON or Reference.EntitiesObjectData[object.Name][0] == Reference.OBJ_STANDARD:
  1756.                 weaponData = Reference.EntitiesObjectData[object.Name]
  1757.                 if len(weaponData) > 4:
  1758.                     throw_style = weaponData[4]
  1759.                 
  1760.             
  1761.         else:
  1762.             kind = Bladex.GetEntity(object.Name).Kind
  1763.             if Reference.DefaultObjectData.has_key(kind):
  1764.                 if Reference.DefaultObjectData[kind][0] == Reference.OBJ_WEAPON or Reference.DefaultObjectData[kind][0] == Reference.OBJ_STANDARD:
  1765.                     weaponData = Reference.DefaultObjectData[kind]
  1766.                     if len(weaponData) > 4:
  1767.                         throw_style = weaponData[4]
  1768.                     
  1769.                 
  1770.             
  1771.         object.ExclusionMask = object.ExclusionMask | B_SOLID_MASK_PERSON
  1772.         if throw_style == Reference.THR_SPINNING:
  1773.             print object.AngularVelocity
  1774.             axis = object.GetDummyAxis('1H_R', 0.0, 1.0, 0.0)
  1775.             mass = object.Mass
  1776.             print mass
  1777.             scale = TWOPI * 10 / mass
  1778.             object.AngularVelocity = (axis[0] * scale, axis[1] * scale, axis[2] * scale)
  1779.         
  1780.         object.MessageEvent(MESSAGE_START_WEAPON, 0, 0)
  1781.         object.MessageEvent(MESSAGE_START_TRAIL, 0, 0)
  1782.         InitDataField.Initialise(object)
  1783.         object.Data.PrevHitFunc = None
  1784.         Bladex.AddScheduledFunc(Bladex.GetTime() + 2.0, ThrownWeaponStopFunc, (object.Name,), 'Stop Weapon: ' + object.Name)
  1785.         object.Data.PrevInflictHitFunc = object.InflictHitFunc
  1786.         object.InflictHitFunc = ThrownWeaponInflictHitFunc
  1787.         object.Data.ThrownBy = me
  1788.  
  1789.     me.DelAnmEventFunc(EventName)
  1790.  
  1791.  
  1792. def StdDropObject(EntityName):
  1793.     me = Bladex.GetEntity(EntityName)
  1794.     if TryDropRight(EntityName):
  1795.         pass
  1796.     elif TryDropLeft(EntityName):
  1797.         pass
  1798.     
  1799.  
  1800.  
  1801. def TryDropRight(EntityName):
  1802.     me = Bladex.GetEntity(EntityName)
  1803.     statR = StatR(EntityName)
  1804.     if statR != RA_NO_WEAPON:
  1805.         object = Bladex.GetEntity(me.InvRight)
  1806.         if IsValidForDropping(object.Name):
  1807.             object.ExcludeHitFor(me)
  1808.             if statR == RA_2H_OBJECT:
  1809.                 me.AddAnmEventFunc('Drop2HandedEvent', DropReleaseEventHandler)
  1810.                 me.LaunchAnmType('drp_2o')
  1811.                 return TRUE
  1812.             else:
  1813.                 me.AddAnmEventFunc('DropRightEvent', DropReleaseEventHandler)
  1814.                 me.Attack = 0
  1815.                 me.LaunchAnmType('drp_r')
  1816.                 return TRUE
  1817.         else:
  1818.             ReportMsg('Cannot be dropped')
  1819.             return FALSE
  1820.     else:
  1821.         return FALSE
  1822.  
  1823.  
  1824. def TryDropLeft(EntityName):
  1825.     me = Bladex.GetEntity(EntityName)
  1826.     statL = StatL(me.Name)
  1827.     if statL != LA_NO_WEAPON and statL != LA_BOW:
  1828.         object = Bladex.GetEntity(me.InvLeft)
  1829.         if IsValidForDropping(object.Name):
  1830.             object.ExcludeHitFor(me)
  1831.             me.AddAnmEventFunc('DropLeftEvent', DropReleaseEventHandler)
  1832.             me.LaunchAnmType('drp_l')
  1833.             return TRUE
  1834.         else:
  1835.             ReportMsg('Cannot be dropped')
  1836.     else:
  1837.         return FALSE
  1838.  
  1839.  
  1840. def DropReleaseEventHandler(EntityName, EventName, TestHit = TRUE):
  1841.     me = Bladex.GetEntity(EntityName)
  1842.     if EventName == 'DropLeftEvent':
  1843.         object = Bladex.GetEntity(me.InvLeft)
  1844.     else:
  1845.         object = Bladex.GetEntity(me.InvRight)
  1846.     
  1847.     try:
  1848.         object.Data.DropReleaseEventHandler(me.Name, EventName)
  1849.     except AttributeError:
  1850.         if TestHit and object.TestHit:
  1851.             return None
  1852.         
  1853.         RemoveFromInventory(me, object, EventName)
  1854.         if EventName == 'DropLeftEvent':
  1855.             impulse = me.Rel2AbsVector(500.0, -750.0, 0.0)
  1856.         elif EventName == 'Drop2HandedEvent':
  1857.             impulse = me.Rel2AbsVector(0.0, -750.0, 0.0)
  1858.         else:
  1859.             impulse = me.Rel2AbsVector(-1000.0, -1500.0, 0.0)
  1860.         object.Impulse(impulse[0], impulse[1], impulse[2])
  1861.         object.ExcludeHitFor(me)
  1862.         me.DelAnmEventFunc(EventName)
  1863.  
  1864.  
  1865.  
  1866. def SqDistanceToGpj(entity):
  1867.     return Gpj.SQDistance2(entity)
  1868.  
  1869.  
  1870. def SthOnBack(EntityName):
  1871.     me = Bladex.GetEntity(EntityName)
  1872.     if me.InvLeftBack:
  1873.         return TRUE
  1874.     
  1875.     if me.InvRightBack:
  1876.         if Reference.GiveObjectFlag(me.InvRightBack) == Reference.OBJ_QUIVER:
  1877.             return FALSE
  1878.         else:
  1879.             return TRUE
  1880.     else:
  1881.         return FALSE
  1882.  
  1883.  
  1884. def TwoHandedWeaponOnBack(EntityName):
  1885.     me = Bladex.GetEntity(EntityName)
  1886.     if SthOnBack(EntityName) and me.InvRightBack:
  1887.         back_object_flag = Reference.GiveObjectFlag(me.InvRightBack)
  1888.         if back_object_flag == Reference.OBJ_WEAPON:
  1889.             w_flag = Reference.GiveWeaponFlag(me.InvRightBack)
  1890.             if w_flag != Reference.W_FLAG_1H:
  1891.                 return TRUE
  1892.             
  1893.         
  1894.     
  1895.     return FALSE
  1896.  
  1897.  
  1898. def Left2InvEvent(pj_name, event):
  1899.     me = Bladex.GetEntity(pj_name)
  1900.     me.DelAnmEventFunc(event)
  1901.     inv = me.GetInventory()
  1902.     if me.InvLeft:
  1903.         inv.LinkLeftHand('None')
  1904.     
  1905.  
  1906.  
  1907. def Left2BackEvent(pj_name, event):
  1908.     me = Bladex.GetEntity(pj_name)
  1909.     me.DelAnmEventFunc(event)
  1910.     inv = me.GetInventory()
  1911.     if me.InvLeft:
  1912.         inv.LinkLeftBack(me.InvLeft)
  1913.     
  1914.  
  1915.  
  1916. def ToggleWEvent(pj_name, event):
  1917.     me = Bladex.GetEntity(pj_name)
  1918.     if IsRightHandStandardObject(pj_name):
  1919.         DropReleaseEventHandler(pj_name, 'DropRightEvent')
  1920.         if me.InvRight:
  1921.             print 'Actions.ToggleWEvent-> Could not drop standard object!'
  1922.             return FALSE
  1923.         
  1924.         me.Wuea = Reference.WUEA_ENDED
  1925.     
  1926.     if event == 'ChangeRLEvent':
  1927.         me.DelAnmEventFunc('ChangeRLEvent')
  1928.     elif event == 'ChangeREvent':
  1929.         me.DelAnmEventFunc('ChangeREvent')
  1930.     elif event == 'ChangeLEvent':
  1931.         me.DelAnmEventFunc('ChangeLEvent')
  1932.     else:
  1933.         print 'ToggleWEvent : Unexpected error! \n'
  1934.     inv = me.GetInventory()
  1935.     tmp_rback = me.InvRightBack
  1936.     tmp_lback = me.InvLeftBack
  1937.     if tmp_rback:
  1938.         if Reference.GiveObjectFlag(tmp_rback) == Reference.OBJ_QUIVER:
  1939.             tmp_rback = ''
  1940.         
  1941.     
  1942.     something_on_back = SthOnBack(pj_name)
  1943.     inv.LinkBack('None')
  1944.     add_quiver = 0
  1945.     if something_on_back and event == 'ChangeRLEvent' or event == 'ChangeREvent':
  1946.         if me.InvRight:
  1947.             inv.LinkRightHand('None')
  1948.         
  1949.         if tmp_lback and Reference.GiveObjectFlag(tmp_lback) == Reference.OBJ_BOW:
  1950.             add_quiver = 1
  1951.         
  1952.         if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  1953.             add_quiver = 1
  1954.         
  1955.     
  1956.     if event == 'ChangeRLEvent' or event == 'ChangeREvent':
  1957.         if me.InvRight:
  1958.             if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW and me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  1959.                 SheatheArrow(inv, me.InvRight)
  1960.             else:
  1961.                 inv.LinkBack(me.InvRight)
  1962.         elif inv.HoldingBow:
  1963.             des_quiver_name = inv.GetSelectedQuiver()
  1964.             if des_quiver_name:
  1965.                 inv.SetCurrentQuiver(des_quiver_name)
  1966.                 inv.LinkRightBack(des_quiver_name)
  1967.             
  1968.         
  1969.         if not tmp_rback:
  1970.             inv.LinkRightHand('None')
  1971.         else:
  1972.             inv.LinkRightHand(tmp_rback)
  1973.             tmp_rback = ''
  1974.     
  1975.     if event == 'ChangeRLEvent' or event == 'ChangeLEvent':
  1976.         if tmp_rback:
  1977.             print 'Pseudo bug? ERROR , MIRAR'
  1978.             inv.LinkBack(tmp_rback)
  1979.         
  1980.         if me.InvLeft:
  1981.             inv.LinkBack(me.InvLeft)
  1982.         
  1983.         if not tmp_lback:
  1984.             inv.LinkLeftHand('None')
  1985.         else:
  1986.             inv.LinkLeftHand(tmp_lback)
  1987.     
  1988.     if add_quiver:
  1989.         UnSheatheArrow(inv)
  1990.     
  1991.  
  1992.  
  1993. def StdToggleWeapons(EntityName):
  1994.     me = Bladex.GetEntity(EntityName)
  1995.     if me.ActiveEnemy:
  1996.         me.SetActiveEnemy('')
  1997.         me.Data.time_deactive_enemy = Bladex.GetTime()
  1998.         return None
  1999.     
  2000.     if me.OnFloor == 0:
  2001.         return None
  2002.     
  2003.     if me.AnmEndedFunc:
  2004.         return FALSE
  2005.     
  2006.     inv = me.GetInventory()
  2007.     right_standard = IsRightHandStandardObject(EntityName)
  2008.     drop_right = 0
  2009.     if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) != Reference.OBJ_BOW and me.InvRightBack:
  2010.         if not (me.Attack) and not (me.Block):
  2011.             me.AddAnmEventFunc('ChangeLEvent', Left2BackEvent)
  2012.             me.LaunchAnmType('Chg_l')
  2013.             return None
  2014.         else:
  2015.             me.AddAnmEventFunc('ChangeREvent', ToggleWEvent)
  2016.             me.LaunchAnmType('Chg_r')
  2017.             return None
  2018.     elif me.InvRight and right_standard == 1:
  2019.         if (me.InvLeft or me.InvLeftBack) and me.InvRightBack and not (inv.HasBowOnBack):
  2020.             me.AddAnmEventFunc('ChangeLEvent', ToggleWEvent)
  2021.             me.LaunchAnmType('Chg_l')
  2022.             return None
  2023.         elif (me.InvRight and right_standard == 0 or me.InvRightBack) and me.InvLeft or me.InvLeftBack:
  2024.             drop_right = 1
  2025.             if inv.HasBowOnBack:
  2026.                 if right_standard:
  2027.                     object = Bladex.GetEntity(me.InvRight)
  2028.                     object.ExcludeHitFor(me)
  2029.                     if not (object.TestHit):
  2030.                         if TryDropRight(EntityName):
  2031.                             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  2032.                             me.Wuea = Reference.WUEA_ENDED
  2033.                         else:
  2034.                             me.Wuea = Reference.WUEA_ENDED
  2035.                             return None
  2036.                     else:
  2037.                         ReportMsg('Cannot be dropped')
  2038.                         return None
  2039.                 
  2040.             
  2041.         elif (me.InvRight and right_standard == 0 or me.InvRightBack) and not (me.InvLeft) and not (me.InvLeftBack):
  2042.             drop_right = 2
  2043.         elif not (me.InvRight) and not (me.InvRightBack) and me.InvLeft or me.InvLeftBack:
  2044.             if inv.HasBowOnBack:
  2045.                 if right_standard:
  2046.                     object = Bladex.GetEntity(me.InvRight)
  2047.                     object.ExcludeHitFor(me)
  2048.                     if not (object.TestHit):
  2049.                         if TryDropRight(EntityName):
  2050.                             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  2051.                             me.Wuea = Reference.WUEA_ENDED
  2052.                         else:
  2053.                             me.Wuea = Reference.WUEA_ENDED
  2054.                             return None
  2055.                     else:
  2056.                         ReportMsg('Cannot be dropped')
  2057.                         return None
  2058.                 
  2059.                 me.AddAnmEventFunc('ChangeRLEvent', ToggleWEvent)
  2060.                 me.LaunchAnmType('Chg_r_l')
  2061.                 return None
  2062.             else:
  2063.                 me.AddAnmEventFunc('ChangeLEvent', ToggleWEvent)
  2064.                 me.LaunchAnmType('Chg_l')
  2065.                 return None
  2066.         else:
  2067.             return None
  2068.     if drop_right != 0 and IsRightHandStandardObject(EntityName):
  2069.         if TryDropRight(EntityName):
  2070.             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  2071.         
  2072.         me.Wuea = Reference.WUEA_ENDED
  2073.     
  2074.     if drop_right == 1:
  2075.         me.AddAnmEventFunc('ChangeRLEvent', ToggleWEvent)
  2076.         me.LaunchAnmType('Chg_r_l')
  2077.     elif drop_right == 2:
  2078.         me.AddAnmEventFunc('ChangeREvent', ToggleWEvent)
  2079.         me.LaunchAnmType('Chg_r')
  2080.     else:
  2081.         print 'ERROR - ToggleW'
  2082.  
  2083.  
  2084. def FreeBothHands(EntityName, CallBack = None, Params = (), ForceNow = 1):
  2085.     me = Bladex.GetEntity(EntityName)
  2086.     if IsRightHandStandardObject(EntityName):
  2087.         if TryDropRight(EntityName):
  2088.             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  2089.         
  2090.         me.Wuea = Reference.WUEA_ENDED
  2091.     
  2092.     if me.InvRight or me.InvLeft:
  2093.         if ForceNow:
  2094.             me.Wuea = Reference.WUEA_ENDED
  2095.             me.SetTmpAnmFlags(1, 1, 1, 0, 5, 1, 0)
  2096.             me.LaunchAnmType('rlx')
  2097.             me.Wuea = Reference.WUEA_ENDED
  2098.             me.SetTmpAnmFlags(1, 1, 1, 0, 5, 1, 0)
  2099.         
  2100.         StdToggleWeapons(EntityName)
  2101.         if CallBack:
  2102.             Bladex.AddScheduledFunc(Bladex.GetTime() + 2.0, CallBack, Params)
  2103.         
  2104.         return 0
  2105.     
  2106.     if CallBack:
  2107.         Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1, CallBack, Params)
  2108.     
  2109.     return 1
  2110.  
  2111.  
  2112. def RelaxTurn180(EntityName):
  2113.     me = Bladex.GetEntity(EntityName)
  2114.     me.LaunchAnmType('rlx_turn')
  2115.  
  2116. import BInput
  2117.  
  2118. def FrwdDown(EntityName):
  2119.     me = Bladex.GetEntity(EntityName)
  2120.     if netgame.GetNetState() != 2:
  2121.         if me.InCombat:
  2122.             return None
  2123.         
  2124.     
  2125.     binput_time_down = BInput.GetInputManager().GetTimeActionActivated('FrwdDown')
  2126.     diff = binput_time_down - me.Data.last_frwdup
  2127.     if diff > 0.0 and diff < 0.125:
  2128.         me = Bladex.GetEntity(EntityName)
  2129.         me.Run = 1
  2130.     
  2131.  
  2132.  
  2133. def FrwdUp(EntityName):
  2134.     me = Bladex.GetEntity(EntityName)
  2135.     if netgame.GetNetState() != 2:
  2136.         if me.InCombat:
  2137.             return None
  2138.         
  2139.     
  2140.     me.Data.last_frwdup = BInput.GetInputManager().GetTimeActionActivated('FrwdUp')
  2141.     if me.Gob == FALSE:
  2142.         me.Run = 0
  2143.     
  2144.  
  2145.  
  2146. def BrwdDown(EntityName):
  2147.     me = Bladex.GetEntity(EntityName)
  2148.     if netgame.GetNetState() != 2:
  2149.         if me.InCombat:
  2150.             return None
  2151.         
  2152.     
  2153.     binput_time_down = BInput.GetInputManager().GetTimeActionActivated('BrwdDown')
  2154.     diff = Bladex.GetTime() - me.Data.last_brwdup
  2155.     if diff > 0.0 and diff < 0.125:
  2156.         me = Bladex.GetEntity(EntityName)
  2157.         me.Run = 1
  2158.     
  2159.  
  2160.  
  2161. def BrwdUp(EntityName):
  2162.     me = Bladex.GetEntity(EntityName)
  2163.     if netgame.GetNetState() != 2:
  2164.         if me.InCombat:
  2165.             return None
  2166.         
  2167.     
  2168.     me.Data.last_brwdup = BInput.GetInputManager().GetTimeActionActivated('BrwdUp')
  2169.     if me.Gof == FALSE:
  2170.         me.Run = 0
  2171.     
  2172.  
  2173.  
  2174. def TakeArrowEventHandler(EntityName, EventName):
  2175.     me = Bladex.GetEntity(EntityName)
  2176.     if me:
  2177.         inv = me.GetInventory()
  2178.         UnSheatheArrow(inv)
  2179.     
  2180.  
  2181.  
  2182. def CurrentlyBowing(EntityName):
  2183.     me = Bladex.GetEntity(EntityName)
  2184.     anm = me.AnimName
  2185.     if not anm == 'B1' and anm == 'B2' and anm == 'B3' and anm == 'b1' and anm == 'b2':
  2186.         pass
  2187.     return anm == 'b3'
  2188.  
  2189.  
  2190. def InitBowing(EntityName):
  2191.     me = Bladex.GetEntity(EntityName)
  2192.     cam = Bladex.GetEntity('Camera')
  2193.     if EntityName == 'Player1':
  2194.         
  2195.         try:
  2196.             if me.Data.LastPViewType == None:
  2197.                 me.Data.LastPViewType = cam.PViewType
  2198.         except AttributeError:
  2199.             me.Data.LastPViewType = cam.PViewType
  2200.  
  2201.         
  2202.         try:
  2203.             if me.Data.LastReturns == None:
  2204.                 me.Data.LastReturns = me.Returns
  2205.         except AttributeError:
  2206.             me.Data.LastReturns = me.Returns
  2207.  
  2208.         cam.PViewType = 3
  2209.     
  2210.     me.Returns = 0
  2211.     me.Aim = 1
  2212.     me.Data.AimPressed = 1
  2213.     me.Accuracy = CharStats.GetCharAccuracy(me.Kind, me.Level)
  2214.     me.AimOffTarget = TWOPI
  2215.  
  2216.  
  2217. def TestDrawBow(EntityName):
  2218.     me = Bladex.GetEntity(EntityName)
  2219.     if me.Aim == 0 or not CurrentlyBowing(EntityName):
  2220.         if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  2221.             if me.Wuea == Reference.WUEA_WAIT:
  2222.                 if me.AnimName[:3] == 'Rlx' or me.AnimName[:3] == 'rlx':
  2223.                     me.Wuea = Reference.WUEA_NONE
  2224.                 else:
  2225.                     return None
  2226.             
  2227.             if me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  2228.                 InitBowing(EntityName)
  2229.                 GraspString(EntityName, 'GraspString')
  2230.                 me.SetTmpAnmFlags(1, 0, 1, 1, 2, 0)
  2231.                 me.LaunchAnmType('b1')
  2232.                 arrow = Bladex.GetEntity(me.InvRight)
  2233.                 tensar_sound = Bladex.CreateEntity(arrow.Name + 'RedrawSound', 'Entity Sound', 0, 0, 0)
  2234.                 tensar_sound.SetSound('..\\..\\Sounds\\M-CREAKCUERDA-3b.wav')
  2235.                 tensar_sound.MinDistance = 5000
  2236.                 tensar_sound.MaxDistance = 10000
  2237.                 arrow.Link(tensar_sound)
  2238.                 tensar_sound.PlaySound(0)
  2239.             elif not CurrentlyBowing(EntityName):
  2240.                 inv = me.GetInventory()
  2241.                 des_quiver_name = inv.GetSelectedQuiver()
  2242.                 if des_quiver_name:
  2243.                     inv.SetCurrentQuiver(des_quiver_name)
  2244.                     inv.LinkRightBack(des_quiver_name)
  2245.                     quiver = Bladex.GetEntity(des_quiver_name)
  2246.                     if quiver and quiver.Data.NumberOfArrows() > 0:
  2247.                         InitBowing(EntityName)
  2248.                         if me.Wuea == Reference.WUEA_WAIT:
  2249.                             print 'Trying to draw bow during other animation, wait and try again'
  2250.                         else:
  2251.                             me.LaunchAnmType('b2')
  2252.                     
  2253.                 
  2254.             
  2255.         
  2256.     
  2257.  
  2258.  
  2259. def EndBowMode(EntityName):
  2260.     me = Bladex.GetEntity(EntityName)
  2261.     
  2262.     try:
  2263.         if me.Data.LastPViewType != None:
  2264.             cam = Bladex.GetEntity('Camera')
  2265.             cam.PViewType = me.Data.LastPViewType
  2266.             me.Data.LastPViewType = None
  2267.     except AttributeError:
  2268.         pass
  2269.  
  2270.     
  2271.     try:
  2272.         if me.Data.LastReturns != None:
  2273.             me.Returns = me.Data.LastReturns
  2274.             me.Data.LastReturns = None
  2275.     except AttributeError:
  2276.         pass
  2277.  
  2278.     me.Aim = 0
  2279.     me.Data.AimPressed = 0
  2280.  
  2281.  
  2282. def TestReleaseArrow(EntityName):
  2283.     me = Bladex.GetEntity(EntityName)
  2284.     me.Data.AimPressed = 0
  2285.     if not CurrentlyBowing(EntityName):
  2286.         EndBowMode(EntityName)
  2287.     
  2288.  
  2289.  
  2290. def EndDrawBowEventHandler(EntityName, EventName):
  2291.     me = Bladex.GetEntity(EntityName)
  2292.     if me.Data.AimPressed == 0:
  2293.         me.Aim = 0
  2294.         arrow = Bladex.GetEntity(me.InvRight)
  2295.         if arrow:
  2296.             me.Unlink(arrow)
  2297.             me.RemoveFromInventRight()
  2298.             UnGraspString(EntityName, 'UnGraspString')
  2299.             arrow.ExcludeHitFor(me)
  2300.             arrow.PutToWorld()
  2301.             if me.Data.NPC:
  2302.                 (vx, vy, vz) = me.AimVector
  2303.             else:
  2304.                 (vx, vy, vz) = arrow.Rel2AbsVector(0, 0, -40000)
  2305.             arrow.Fly(vx, vy, vz)
  2306.             arrow.MessageEvent(MESSAGE_START_WEAPON, 0, 0)
  2307.             arrow.MessageEvent(MESSAGE_START_TRAIL, 0, 0)
  2308.             InitDataField.Initialise(arrow)
  2309.             Bladex.AddScheduledFunc(Bladex.GetTime() + 2.0, ThrownWeaponStopFunc, (arrow.Name,), 'Stop Weapon: ' + arrow.Name)
  2310.             arrow.Data.PrevInflictHitFunc = arrow.InflictHitFunc
  2311.             arrow.InflictHitFunc = ThrownWeaponInflictHitFunc
  2312.             arrow.Data.ThrownBy = me
  2313.             soltar_sound = Bladex.CreateEntity(arrow.Name + 'FlySound', 'Entity Sound', 0, 0, 0)
  2314.             soltar_sound.SetSound('..\\..\\Sounds\\ARCO-DISPARO-3.wav')
  2315.             soltar_sound.MinDistance = 5000
  2316.             soltar_sound.MaxDistance = 10000
  2317.             arrow.Link(soltar_sound)
  2318.             soltar_sound.PlaySound(0)
  2319.             me.SetTmpAnmFlags(1, 0, 1, 1, 2, 0)
  2320.             me.LaunchAnmType('b2')
  2321.             return None
  2322.         
  2323.     
  2324.     me.LaunchAnmType('b3')
  2325.  
  2326.  
  2327. def CheckRefireBowEventHandler(EntityName, EventName):
  2328.     me = Bladex.GetEntity(EntityName)
  2329.     if me.InvRight:
  2330.         action = BInput.GetInputManager().GetInputActions().Find('Attack')
  2331.         if action and action.this != 'NULL' and action.CurrentlyActivated():
  2332.             me.Aim = 1
  2333.             me.Data.AimPressed = 1
  2334.         
  2335.         if me.Data.AimPressed:
  2336.             arrow = Bladex.GetEntity(me.InvRight)
  2337.             if arrow:
  2338.                 GraspString(EntityName, 'GraspString')
  2339.                 me.DoActionWI('b1', FixedFootAutoInterp, 0.3, 0.9)
  2340.                 tensar_sound = Bladex.CreateEntity(arrow.Name + 'RedrawSound', 'Entity Sound', 0, 0, 0)
  2341.                 tensar_sound.SetSound('..\\..\\Sounds\\M-CREAKCUERDA-44.wav')
  2342.                 tensar_sound.MinDistance = 5000
  2343.                 tensar_sound.MaxDistance = 10000
  2344.                 arrow.Link(tensar_sound)
  2345.                 tensar_sound.PlaySound(0)
  2346.                 return None
  2347.             
  2348.         
  2349.     
  2350.     EndBowMode(EntityName)
  2351.  
  2352.  
  2353. def EndReloadBowEventHandler(EntityName, EventName):
  2354.     me = Bladex.GetEntity(EntityName)
  2355.     if me.Aim:
  2356.         me.DoAction('b1')
  2357.     elif not (me.InvRight):
  2358.         TakeArrowEventHandler(EntityName, EventName)
  2359.     
  2360.     me.LaunchAnmType('Rlx_b')
  2361.  
  2362.  
  2363. def FadeMeOut(EntityName, timer):
  2364.     if EntityName == 'Player1':
  2365.         return None
  2366.     
  2367.     me = Bladex.GetEntity(EntityName)
  2368.     current_alpha = me.Alpha
  2369.     if current_alpha > 0.0:
  2370.         current_alpha = current_alpha - 0.02
  2371.     else:
  2372.         me.Life = 0
  2373.         me.RemoveFromList('Timer60')
  2374.     if current_alpha < 0:
  2375.         current_alpha = 0
  2376.     
  2377.     me.Alpha = current_alpha
  2378.     if me.InvRight:
  2379.         right = Bladex.GetEntity(me.InvRight)
  2380.         right.Alpha = current_alpha
  2381.     
  2382.     if me.InvLeft:
  2383.         left = Bladex.GetEntity(me.InvLeft)
  2384.         left.Alpha = current_alpha
  2385.     
  2386.     if me.InvRightBack:
  2387.         right2 = Bladex.GetEntity(me.InvRightBack)
  2388.         right2.Alpha = current_alpha
  2389.     
  2390.     if me.InvLeftBack:
  2391.         left2 = Bladex.GetEntity(me.InvLeftBack)
  2392.         left2.Alpha = current_alpha
  2393.     
  2394.  
  2395.  
  2396. def ClientCallBack(id, type, cad):
  2397.     if type == Netval.NET_GAME_FADE_DUE2BIGFALL:
  2398.         if netgame.GetClientId() == cad:
  2399.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL, END_FADEOUT_IN_BIG_FALL)
  2400.         
  2401.     
  2402.  
  2403.  
  2404. def ServerCallBack(id, type, cad):
  2405.     if type == Netval.NET_GAME_THROW_WEAPON:
  2406.         if netgame.GetNetState() == 1:
  2407.             params = string.split(cad)
  2408.             me = Bladex.GetEntity(params[0])
  2409.             coso = string.atof(params[1])
  2410.             if coso == -1:
  2411.                 TryDropRight(params[0])
  2412.             else:
  2413.                 me.Data.ThrowForce = coso
  2414.                 StdThrowObject(params[0])
  2415.         
  2416.     
  2417.  
  2418.  
  2419. def StartFadingOutPlayer(EntityName):
  2420.     me = Bladex.GetEntity(EntityName)
  2421.     net_state = netgame.GetNetState()
  2422.     if net_state == 0:
  2423.         if EntityName == 'Player1' and me.WillCrashInFloor == 0:
  2424.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL, END_FADEOUT_IN_BIG_FALL)
  2425.         
  2426.     elif EntityName == 'Player1':
  2427.         if me.WillCrashInFloor == 0:
  2428.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL, END_FADEOUT_IN_BIG_FALL)
  2429.         
  2430.         netgame.SendUserString(Netval.NET_GAME_FADE_DUE2BIGFALL, EntityName)
  2431.     else:
  2432.         netgame.SendUserString(Netval.NET_GAME_FADE_DUE2BIGFALL, EntityName)
  2433.         me.TimerFunc = FadeMeOut
  2434.         me.SubscribeToList('Timer60')
  2435.  
  2436.  
  2437. def EndFadingOutPlayer(EntityName):
  2438.     me = Bladex.GetEntity(EntityName)
  2439.     me.Life = 0
  2440.     net_state = netgame.GetNetState()
  2441.     me.Wuea = Reference.WUEA_ENDED
  2442.     if net_state == 0:
  2443.         me.ImDeadFunc(me.Name)
  2444.         if EntityName == 'Player1':
  2445.             if me.WillCrashInFloor == 0:
  2446.                 int_pos = me.InitPos
  2447.                 me.Position = (int_pos[0], int_pos[1], int_pos[2])
  2448.             else:
  2449.                 int_pos = me.InitPos
  2450.                 me.Position = (int_pos[0], int_pos[1], int_pos[2])
  2451.         
  2452.     elif net_state == 1:
  2453.         me.Alpha = 1.0
  2454.         Damage.PlayerHitFunc(me.Name, 'BigFall', me.Life, 1)
  2455.     elif net_state == 2:
  2456.         me.Alpha = 1.0
  2457.     else:
  2458.         print 'Actions.py->EndFadingOutPlayer error . Unknown GetNetState()!!!'
  2459.  
  2460.  
  2461. def LinkNextAttack(EntityName, EventName):
  2462.     me = Bladex.GetEntity(EntityName)
  2463.     if me:
  2464.         me.RaiseEvent('HitFinalItpC')
  2465.     
  2466.     if not (me.Data.NPC):
  2467.         Select.AutoSelectInAttack(EntityName)
  2468.     
  2469.  
  2470.  
  2471. def EndOfAttack(EntityName, EventName):
  2472.     me = Bladex.GetEntity(EntityName)
  2473.     if me:
  2474.         me.RaiseEvent('ActionEndC')
  2475.     
  2476.     if not (me.Data.NPC):
  2477.         Select.AutoSelectInAttack(EntityName)
  2478.     
  2479.  
  2480.  
  2481. def BackUpEnemy(EntityName, EventName):
  2482.     me = Bladex.GetEntity(EntityName)
  2483.     me.Data.TmpEnemy = me.ActiveEnemy
  2484.  
  2485.  
  2486. def Swap180Handler(EntityName, EventName):
  2487.     me = Bladex.GetEntity(EntityName)
  2488.     if me.Data and me.Data.TmpEnemy and me.Data.TmpEnemy == me.ActiveEnemy:
  2489.         me.SetActiveEnemy(None)
  2490.         if me.Data.selected_enemy:
  2491.             ene = Bladex.GetEntity(me.Data.selected_enemy[0])
  2492.             if me and ene.Person:
  2493.                 me.SetActiveEnemy(ene)
  2494.             
  2495.         
  2496.     elif me.Data.selected_enemy:
  2497.         ene = Bladex.GetEntity(me.Data.selected_enemy[0])
  2498.         if me and ene.Person:
  2499.             me.SetActiveEnemy(ene)
  2500.         
  2501.     
  2502.  
  2503.  
  2504. def EndTransitionFllHugeHandler(EntityName, EventName):
  2505.     me = Bladex.GetEntity(EntityName)
  2506.     Bladex.AddScheduledFunc(Bladex.GetTime() + 0.2, StartFadingOutPlayer, (EntityName,), 'StartFadingOutPlayer ' + EntityName)
  2507.     me.AnmEndedFunc = TakeMainAnm = EndFadingOutPlayer
  2508.  
  2509.  
  2510. def W2hToLeftHandler(EntityName, EventName):
  2511.     me = Bladex.GetEntity(EntityName)
  2512.     ObjectName = me.InvRight
  2513.     if ObjectName == 'None' or not ObjectName:
  2514.         print 'W2hToLeftHandle-> Event in a unexpected situation!!! Entity ' + EntityName + ' in animation ' + me.AnimName
  2515.         return None
  2516.     
  2517.     inv = me.GetInventory()
  2518.     inv.LinkRightHand('None')
  2519.     object = Bladex.GetEntity(ObjectName)
  2520.     node = me.GetNodeIndex('L_Hand')
  2521.     me.LinkToNode(object, node)
  2522.     me.Data.TmpW2h = ObjectName
  2523.  
  2524.  
  2525. def W2hToRightHandler(EntityName, EventName):
  2526.     me = Bladex.GetEntity(EntityName)
  2527.     if not ('TmpW2h' in dir(me.Data)):
  2528.         me.Data.TmpW2h = ''
  2529.         return None
  2530.     
  2531.     if me.Data.TmpW2h == None:
  2532.         return None
  2533.     
  2534.     if me.Data.TmpW2h == '':
  2535.         return None
  2536.     
  2537.     inv = me.GetInventory()
  2538.     object = Bladex.GetEntity(me.Data.TmpW2h)
  2539.     me.Unlink(object)
  2540.     inv.LinkLeftHand('None')
  2541.     inv.LinkRightHand(me.Data.TmpW2h)
  2542.     me.Data.TmpW2h = ''
  2543.  
  2544.  
  2545. def AutoTake(EntityName):
  2546.     me = Bladex.GetEntity(EntityName)
  2547.     if me.InvRight:
  2548.         if not FreeBothHands(EntityName, None, (), 0):
  2549.             return None
  2550.         
  2551.     
  2552.     head_pos = me.Rel2AbsPoint(0.0, 0.0, 0.0)
  2553.     pj_dir = me.Rel2AbsVector(0.0, -1.0, 0.0)
  2554.     list = Bladex.GetObjectEntitiesVisibleFrom(head_pos, 5000.0, pj_dir, 0.0)
  2555.     for n in list:
  2556.         o = Bladex.GetEntity(n)
  2557.     
  2558.  
  2559.  
  2560. def ToggleIAttackRight(EntityName, event):
  2561.     me = Bladex.GetEntity(EntityName)
  2562.     if not (me.InvRightBack) or me.InvRightBack == '':
  2563.         print 'Error in Actions.ToggleIAttackRight'
  2564.         return None
  2565.     
  2566.     inv = me.GetInventory()
  2567.     tmpr_back = me.InvRightBack
  2568.     inv.LinkRightBack('None')
  2569.     inv.LinkRightHand(tmpr_back)
  2570.     if not (me.InCombat):
  2571.         import DefaultSelectionData
  2572.         DefaultSelectionData.SelectEnemy()
  2573.     
  2574.  
  2575.  
  2576. def ToggleIAttackLeft(EntityName, event):
  2577.     me = Bladex.GetEntity(EntityName)
  2578.     if not (me.InvLeftBack) or me.InvLeftBack == '':
  2579.         return None
  2580.     
  2581.     inv = me.GetInventory()
  2582.     tmpl_back = me.InvLeftBack
  2583.     inv.LinkLeftBack('None')
  2584.     inv.LinkLeftHand(tmpl_back)
  2585.  
  2586.  
  2587. def InstantAttackSlow(EntityName, EventName):
  2588.     me = Bladex.GetEntity(EntityName)
  2589.     if not (me.Data.NPC) and me.GotAnmType('g_draw_rlx'):
  2590.         me.AddAnmEventFunc('ChangeREvent', ToggleIAttackRight)
  2591.         me.AddAnmEventFunc('ChangeLEvent', ToggleIAttackLeft)
  2592.         me.AttackFunc(EntityName, 'g_draw_rlx')
  2593.     elif not (me.Data.NPC):
  2594.         print 'No instant attack for not having the animation!! ----3D Dept---' + EntityName
  2595.     
  2596.  
  2597.  
  2598. def InstantAttackRun(EntityName, EventName):
  2599.     me = Bladex.GetEntity(EntityName)
  2600.     if me.GotAnmType('g_draw_run'):
  2601.         me.AddAnmEventFunc('ChangeREvent', ToggleIAttackRight)
  2602.         me.AddAnmEventFunc('ChangeLEvent', ToggleIAttackLeft)
  2603.         me.AttackFunc(EntityName, 'g_draw_run')
  2604.     elif me.Data.NPC == 0:
  2605.         print 'No instant attack for not having the animation!! ----3D Dept---' + EntityName
  2606.     
  2607.  
  2608.  
  2609. def LinkContinuosSoundAux(csound):
  2610.     csound.PlaySound(-1)
  2611.  
  2612.  
  2613. def LinkContinuosSound(EntityName, SoundName, max_dist = 12000, min_dist = 5000):
  2614.     me = Bladex.GetEntity(EntityName)
  2615.     csound = Bladex.CreateEntity(EntityName + 'ContinuosSound', 'Entity Sound', 0, 0, 0)
  2616.     csound.SetSound(SoundName)
  2617.     csound.MinDistance = min_dist
  2618.     csound.MaxDistance = max_dist
  2619.     me.Link(csound)
  2620.     Bladex.AddScheduledFunc(Bladex.GetTime() + 1.0, LinkContinuosSoundAux, (csound,), 'LinkContinuosSoundAux')
  2621.  
  2622.  
  2623. def CicloDeluz(PersonName, val):
  2624.     per = Bladex.GetEntity(PersonName)
  2625.     if per:
  2626.         if val < 1.0:
  2627.             per.SelfIlum = val
  2628.             Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1, CicloDeluz, (PersonName, val + 0.1))
  2629.             wps = Bladex.GetEntity(PersonName + 'WPS')
  2630.             if wps:
  2631.                 wps.PPS = wps.PPS + 25
  2632.             
  2633.         elif val < 2.0:
  2634.             per.Alpha = -val + 1.9
  2635.             Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1, CicloDeluz, (PersonName, val + 0.1))
  2636.         
  2637.     
  2638.  
  2639.  
  2640. def HumoDeFuego(PersonName):
  2641.     per = Bladex.GetEntity(PersonName)
  2642.     if per:
  2643.         wps = Bladex.CreateEntity(PersonName + 'WPSmk', 'Entity Particle System Dperson', 0.0, 0.0, 0.0)
  2644.         wps.PersonName = PersonName
  2645.         wps.ParticleType = 'DarkSmoke'
  2646.         wps.Time2Live = 96
  2647.         wps.RandomVelocity = 0
  2648.         wps.Velocity = (0, 0, 0)
  2649.         wps.NormalVelocity = 5
  2650.         wps.YGravity = 0
  2651.         wps.PPS = 125
  2652.         wps.DeathTime = Bladex.GetTime() + 1.0
  2653.     
  2654.  
  2655.  
  2656. def FreezeMeGuy(PersonName):
  2657.     import GameText
  2658.     per = Bladex.GetEntity(PersonName)
  2659.     per.Freeze()
  2660.     per.RemoveFromWorld()
  2661.     if netgame.GetNetState() == 0 and Reference.DEMO_MODE == 0 and PersonName == 'Player1' and GameText.MapList.has_key(string.upper(Bladex.GetCurrentMap())):
  2662.         import SaveGame
  2663.         Bladex.AddScheduledFunc(Bladex.GetTime() + 7.0, SaveGame.MenuStart, (PersonName,))
  2664.     
  2665.  
  2666.  
  2667. def RePutTheFuckingEndFunction(PersonName):
  2668.     per = Bladex.GetEntity(PersonName)
  2669.     per.AnmEndedFunc = FreezeMeGuy
  2670.  
  2671.  
  2672. def FireDeath(PersonName = 'Player1', ParType = 'LargeFire', NumPart = 32):
  2673.     TIME_TO_FIRE = 12.0
  2674.     per = Bladex.GetEntity(PersonName)
  2675.     if per:
  2676.         wps = Bladex.CreateEntity(PersonName + 'WPS', 'Entity Particle System Dperson', 0.0, 0.0, 0.0)
  2677.         wps.PersonName = PersonName
  2678.         wps.ParticleType = ParType
  2679.         wps.Time2Live = NumPart
  2680.         wps.RandomVelocity = 1.0
  2681.         wps.Velocity = (0, -300, 0)
  2682.         wps.NormalVelocity = 3
  2683.         wps.YGravity = 0
  2684.         wps.PPS = 200
  2685.         wps.DeathTime = Bladex.GetTime() + TIME_TO_FIRE
  2686.         Bladex.AddScheduledFunc(Bladex.GetTime() + TIME_TO_FIRE - 0, HumoDeFuego, (PersonName,))
  2687.         if netgame.GetNetState() != 2:
  2688.             per.SelfIlum = 0.0
  2689.             per.Alpha = 1.0
  2690.             Bladex.AddScheduledFunc(Bladex.GetTime() + TIME_TO_FIRE - 2, CicloDeluz, (PersonName, 0))
  2691.             Bladex.AddScheduledFunc(Bladex.GetTime() + 1.5, RePutTheFuckingEndFunction, (PersonName,))
  2692.             per.LaunchAnmType('dth_burn')
  2693.             per.AnmEndedFunc = FreezeMeGuy
  2694.             if per.Name == 'Player1':
  2695.                 cam = Bladex.GetEntity('Camera')
  2696.                 cam.SType = 0
  2697.                 cam.TType = 0
  2698.             
  2699.         
  2700.     
  2701.  
  2702.  
  2703. def ToggleInvincibility():
  2704.     me = Bladex.GetEntity('Player1')
  2705.     
  2706.     try:
  2707.         if me:
  2708.             if not (me.Data.Invincibility):
  2709.                 import pocimac
  2710.                 me.Life = CharStats.GetCharMaxLife(me.Kind, me.Level)
  2711.                 pocimac.RestoreWoundsToLifeLevel(me.Name)
  2712.                 me.Data.Invincibility = TRUE
  2713.                 ReportMsg('Enabling INVINCIBILITY mode')
  2714.             else:
  2715.                 me.Data.Invincibility = FALSE
  2716.                 ReportMsg('Disabling INVINCIBILITY mode')
  2717.     except AttributeError:
  2718.         pass
  2719.  
  2720.  
  2721. profiler_on = 1
  2722.  
  2723. def ToggleProfiling():
  2724.     global profiler_on
  2725.     profiler_on = not profiler_on
  2726.     if not profiler_on:
  2727.         print 'Switching off Profiler'
  2728.         Bladex.SetCallCheck(3)
  2729.         Bladex.SaveProfileData('Profile.txt')
  2730.         Bladex.StartProfile()
  2731.         Bladex.DisableProfiler()
  2732.     else:
  2733.         print 'Switching on Profiler'
  2734.         Bladex.SetCallCheck(11)
  2735.         Bladex.EnableProfiler()
  2736.         Bladex.StartProfile()
  2737.  
  2738.  
  2739. def QuickDeath(EntityName, EventName):
  2740.     Bladex.GetEntity(EntityName).Life = 0
  2741.     if EntityName == 'Player1':
  2742.         import SaveGame
  2743.         Bladex.AddScheduledFunc(Bladex.GetTime() + 5.0, SaveGame.MenuStart, (EntityName,))
  2744.         AuxFuncs.FadeTo(3.5, 10.0, 128, 0, 0)
  2745.     
  2746.  
  2747.